MongoDB C# Driver 2.0 - Update document -


i'm upgrading code mongodb c# driver 2.0 , i'm having issues upgrading code update documents.

using old version able this:

mytype myobject; // passed in  var collection = _database.getcollection<mytype>("mytypes"); var result = collection.save(myobject); 

i'm struggling find way in new version. have found few examples of updating single fields like

var filter = builders<mytype>.filter.eq(s => s.id, id); var update = builders<mytype>.update.set(s => s.description, description); var result = await collection.updateoneasync(filter, update); 

i'd update fields doing in old version method save.

any ideas ?

thanks lot

i think you're looking replaceoneasync():

mytype myobject; // passed in  var filter = builders<mytype>.filter.eq(s => s.id, id); var result = await collection.replaceoneasync(filter, myobject) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -