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
Post a Comment