FindOneAndDeleteAsync() in C# with MongoDB

FindOneAndDeleteAsync() 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 Delete it.

In the below example MasterIds is the collection name and MasterID is the column name and deleting the MasterID with value 11630

Result will output you the deleted record data as shown below.

var result = await collection.FindOneAndDeleteAsync(
                   Builders<BsonDocument>.Filter.Eq("MasterID", 11630),
                   new FindOneAndDeleteOptions<BsonDocument>
                   Sort = Builders<BsonDocument>.Sort.Descending("MasterID")