MongoDB atomic update via 'merge' document

后端 未结 1 1345
故里飘歌
故里飘歌 2021-02-10 17:39

I know that I can atomically update an existing Mongo document by setting specific fields. The following code will do it:

var update = MongoDB.Driver.Builders.U         


        
相关标签:
1条回答
  • 2021-02-10 18:03

    Found the answer:

    //var snippetJSON= '{title:"Tin Machine II",brandnewfield:"this gets added nicely"}';
        MongoDB.Bson.BsonDocument updateDoc = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(snippetJSON);
    var update = new UpdateDocument { { "$set", updateDoc } };
    

    Easy when you know how!

    0 讨论(0)
提交回复
热议问题