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

查看:84
本文介绍了删除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();

Ruby代码非常相似.

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

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