Deleting everything in MongoDB database

How to delete everything in MongoDB database?

Use the following command:

use [database];
db.dropDatabase();

This would delete the database.

The dropDatabase command drops a database, deleting the associated data files. dropDatabase operates on the current database.

In the shell issue the use command, replacing with the name of the database you wish to delete. Then use the following command form:

{ dropDatabase: 1 }
The mongo shell also provides the following equivalent helper method:

db.dropDatabase();

In MongoDB, the db.collection.remove() method removes documents from a collection. You can remove all documents from a collection, remove all documents that match a condition, or limit the operation to remove just a single document.

This tutorial provides examples of remove operations using the db.collection.remove() method in the mongo shell.

Remove All Documents

To remove all documents from a collection, pass an empty query document {} to the remove() method. The remove() method does not remove the indexes.

The following example removes all documents from the inventory collection:

db.inventory.remove({})
To remove all documents from a collection, it may be more efficient to use the drop() method to drop the entire collection, including the indexes, and then recreate the collection and rebuild the indexes.

Hello.

Remove an entire Database using dropDatabase()

db.dropDatabase()

Hope it will help

More about MongoDb Visit