如何在C#中使用集合名称删除Mongodb集合 [英] How to Delete a Mongodb collection using collection name in c#

查看:708
本文介绍了如何在C#中使用集合名称删除Mongodb集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在c#中使用mongo在数据库中创建了一个集合.我可以使用ID删除集合中的内容,但不能删除集合.请帮助我如何使用c#

I have created a collection in a database using mongo in c# . Iam able to delete the content in the collection using ID but not the collection .Pls help me how to drop a collection using c#

推荐答案

没什么,只需在集合上调用Drop():

There's not much to it, just call Drop() on the collection:

var test = db.GetCollection("test");
test.Drop();

更新:执行此操作的新C#API方法是:

Update: The new C# API way of doing this is:

db.DropCollection("test");

这篇关于如何在C#中使用集合名称删除Mongodb集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆