如何使用Mongo DB JAVA驱动程序从MongoDB中的数据库删除集合? [英] How to drop collection from database in MongoDB using Mongo DB JAVA driver?

查看:84
本文介绍了如何使用Mongo DB JAVA驱动程序从MongoDB中的数据库删除集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令是使用mongo.exe客户端键入的(假设存在集合 coll ):

The following commands were typed using mongo.exe client (assuming that the collection coll exists) :

> use database
switched to db database
>db.coll.drop()
True

如何使用Mongo DB JAVA驱动程序执行db.coll.drop()?

How to perform db.coll.drop() using Mongo DB JAVA driver?

推荐答案

我认为这应该有效:

MongoClient mongoClient = new MongoClient();
DB db = mongoClient.getDB("mydb");
DBCollection myCollection = db.getCollection("myCollection");
myCollection.drop();

这篇关于如何使用Mongo DB JAVA驱动程序从MongoDB中的数据库删除集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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