How to use $push update modifier in MongoDB and C#, when updating an array in a document

前端 未结 3 1504
独厮守ぢ
独厮守ぢ 2021-01-01 20:56

I\'ve run the following code in mongo shell:

db.unicorns.insert({name:  \'Dunx\',  loves:  [\'grape\',  \'watermelon\']});

and now I\'ve so

3条回答
  •  醉酒成梦
    2021-01-01 21:47

    I would like to also illustrate how to do it using a different syntax

    var filter = Builders
                 .Filter.Eq(e => e.Name, "Aurora");
    
    var update = Builders.Update
            .Push(e => e.Likes, like);
    
    await fantasyContext.Unicorns.FindOneAndUpdateAsync(filter, update);
    

提交回复
热议问题