I have a document that I want to Upsert an array into. Here's the initial document:
{
"_id" : "F_S_17460317_0",
"featureid" : 17460317,
"featuretype" : "S",
"builddate" : ISODate("2012-10-16T13:28:00Z"),
"lastediteddate" : ISODate("2012-05-31T07:23:37.963Z")
}
var query = MongoDB.Driver.Builders.Query.EQ("_id", "F_S_17460317_0");
var update = Update.AddToSet("unifiedassociations",
{
"_id" : "A_C_345_S_17460317_0",
"associationid" : 82152889,
"parentkey" : null,
"containerid" : 345,
"containertype" : "C",
"featureid" : 17460317,
"featuretype" : "S",
"cachedate" : ISODate("2012-10-25T15:24:01.43Z") }
);
_collection.FindAndModify(query, SortBy.Null, update, false, true);
This inserts the array properly, with one element added:
{
"_id" : "F_S_17460317_0",
"featureid" : 17460317,
"featuretype" : "S",
"builddate" : ISODate("2012-10-16T13:28:00Z"),
"lastediteddate" : ISODate("2012-05-31T07:23:37.963Z"),
"unifiedassociations" :
[
{ "_id" : "A_C_345_S_17460317_0",
"associationid" : 82152889,
"parentkey" : null,
"containerid" : 345,
"containertype" : "C",
"featureid" : 17460317,
"featuretype" : "S",
"cachedate" : ISODate("2012-10-25T15:24:01.43Z")
}
]
}
But when I change a field and re-run the query a new record is inserted, even though the _id's are the same:
{
"_id" : "F_S_17460317_0",
"featureid" : 17460317,
"featuretype" : "S",
"builddate" : ISODate("2012-10-16T13:28:00Z"),
"lastediteddate" : ISODate("2012-05-31T07:23:37.963Z"),
"unifiedassociations" :
[
{ "_id" : "A_C_345_S_17460317_0",
"associationid" : 82152889,
"parentkey" : null,
"containerid" : 345,
"containertype" : "C",
"featureid" : 17460317,
"featuretype" : "S",
"cachedate" : ISODate("2012-10-25T14:25:01.43Z")
},
{ "_id" : "A_C_345_S_17460317_0",
"associationid" : 82152889,
"parentkey" : null,
"containerid" : 345,
"containertype" : "C",
"featureid" : 17460317,
"featuretype" : "S",
"cachedate" : ISODate("2012-10-25T15:11:01.43Z")
}
]
}
I've tried a bunch of different calls, but I can't seem to get it to work. I'm not even sure if this is possible.
Help.