How to remove one 'document' by 'ID' using the Official C# Driver for MongoDB?

后端 未结 5 1256
萌比男神i
萌比男神i 2020-12-10 01:09

Can someone please show me, if there is a better way to remove one document from MongoDB using the Official C# Driver than what I have below-

va         


        
5条回答
  •  没有蜡笔的小新
    2020-12-10 01:22

    The Simplest Way

    Remove a document from a collection for C# MongoDB Driver (v2.0 or later)-

    collection.DeleteOne(a => a.Id==id);
    

    Or-

    await collection.DeleteOneAsync(a => a.Id==id);
    

提交回复
热议问题