I\'ve run the following code in mongo shell:
db.unicorns.insert({name: \'Dunx\', loves: [\'grape\', \'watermelon\']});
and now I\'ve so
To do this with the updated syntax and regular BsonDocument
s instead of defined objects, use the following:
var filter = Builders<BsonDocument>.Filter.Eq("name": "Aurora");
var update = Builders<BsonDocument>.Update.Push("loves", "sugar"):
// you can also use the async update method from Alex's answer here
var result = fantasyContext.Unicorns.UpdateOne(filter, update);
it should be something like this:
unicorns.Update(Query.EQ("name", "Aurora"), Update.Push("loves", "sugar"));
I would like to also illustrate how to do it using a different syntax
var filter = Builders<Unicorn>
.Filter.Eq(e => e.Name, "Aurora");
var update = Builders<Unicorn>.Update
.Push<String>(e => e.Likes, like);
await fantasyContext.Unicorns.FindOneAndUpdateAsync(filter, update);