简体   繁体   English

有没有一种简单的方法可以从 C# 中的 MongoDB 集合中删除所有数据?

[英]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.

相关问题 C#MongoDB,从排序后的集合中删除前10名 - C# MongoDB, remove top 10 from sorted collection 是否可以在 C# 中以简单的方式从某个范围内获取数据? - Is it possible to get the data from a range in an easy way in C#? 使用c#驱动程序从mongodb集合中选择所有_id - Select all _id from mongodb collection with c# driver c#打印格式化数据的简便方法 - c# easy way to print formatted data C#AppSettings:有没有简单的方法可以将集合放入<appSetting> - C# AppSettings: Is there a easy way to put a collection into <appSetting> 有没有一种简单的方法可以从C#访问网络摄像头? - Is there an easy way to access the webcam from C#? 在 c# Xamarin 上显示来自 db 的 ListView 数据时,有没有办法从屏幕而不是字符串中删除 System.Collection.Generic 消息 - Is there a way to remove System.Collection.Generic message from screen instead of string when display ListView data from db on c# Xamarin 是否有一种简单的方法可以在C#中向所有表单对象添加事件 - Is there an easy way to add an event to all form objects in C# 在c#中获取所有枚举值的简便方法 - Easy way to get all Enum values in c# C#删除除一个以外的所有数据表的最佳方法 - C# Best way to remove all datatables apart from one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM