简体   繁体   中英

Is there an easy way to remove all data from MongoDB collection in C#?

I want to make a unique method for deleting all data from MongoDB collection in C#.

Before I called only RemoveAll() method and it worked. But now as it has only DeleteOne() i DeleteMany() methods where I should put filter, but as this method should be unique for all collections, I am not sure how to make filter to remove all data from collection without deleting collection.

For Collection it is not specified which one, it should go as a parameter to the method.

Try using an empty BsonDocument to delete all the documents from the collection:

collection.DeleteMany(new BsonDocument());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM