[英]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#.我想用一种独特的方法从 C# 中的 MongoDB 集合中删除所有数据。
Before I called only RemoveAll() method and it worked.在我只调用RemoveAll()方法之前它起作用了。 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.
但现在因为它只有DeleteOne()和DeleteMany()方法,我应该在其中放置过滤器,但由于此方法对于所有 collections 都是唯一的,我不确定如何制作过滤器以从集合中删除所有数据而不删除集合。
For Collection it is not specified which one, it should go as a parameter to the method.对于 Collection 没有指定哪一个,它应该 go 作为方法的参数。
Try using an empty BsonDocument
to delete all the documents from the collection:尝试使用空的
BsonDocument
从集合中删除所有文档:
collection.DeleteMany(new BsonDocument());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.