删除 MongoDB 数据库中的所有内容 [英] Delete everything in a MongoDB database

查看:29
本文介绍了删除 MongoDB 数据库中的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 MongoDB 上进行开发.出于完全非邪恶的目的,有时我想删除数据库中的所有内容——也就是说,删除每个集合,以及可能存在的任何其他内容,然后从头开始.是否有一行代码可以让我做到这一点?提供 MongoDB 控制台方法和 MongoDB Ruby 驱动程序方法的奖励积分.

I'm doing development on MongoDB. For totally non-evil purposes, I sometimes want to blow away everything in a database—that is, to delete every single collection, and whatever else might be lying around, and start from scratch. Is there a single line of code that will let me do this? Bonus points for giving both a MongoDB console method and a MongoDB Ruby driver method.

推荐答案

在 mongo shell 中:

In the mongo shell:

use [database];
db.dropDatabase();

并删除用户:

db.dropAllUsers();

这篇关于删除 MongoDB 数据库中的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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