Using MongoDB, I am unable to add the en element to the array when the array is null. AddToSet works as expected if I add an item from the console. I am using the official C # driver from 10gen.
var query = Query.EQ("_id", objectId);
var itemDoc = item.ToBsonDocument();
var update = MongoDB.Driver.Builders.Update.AddToSet("items", itemDoc);
var workingUpdate = MongoDB.Driver.Builders.Update.AddToSet("somefield", itemDoc);
var collection = DataBase.GetCollection<MyObject>(CollectionName);
collection.Update(query, update);
collection.Update(query, workingUpdate);
Is this the expected behavior? If so, is there a more general way to add elements to an array?
source
share