Skip to main content

FindOneAndUpdateAsync() in C# with MongoDB

FindOneAndUpdateAsync () is introduced in MongoDB driver 2.0 for .Net 4.5 and greater versions of framework, This function is used for Finding the Specific Document and update it.

In the below example FindOneAndUpdateAsync() is used to find the document with ‘MasterID’ as 1110 and replace it with 1120

Example :

var result = await collection.FindOneAndUpdateAsync(
                      Builders<BsonDocument>.Filter.Eq("MasterID", 1110),
                      Builders<BsonDocument>.Update.Set("MasterID", 1120)


Post a Comment