Delete everything in a MongoDB database

Trevor Burnham picture Trevor Burnham · Jul 29, 2010 · Viewed 282.9k times · Source

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.

Answer

Josh K picture Josh K · Jul 29, 2010

In the mongo shell:

use [database];
db.dropDatabase();

And to remove the users:

db.dropAllUsers();