Deleting Databases
Once a database has been created, it exists in MongoDB until an administrator deletes it. Deleting databases is a common task on some systems, especially when databases are created to contain temporary data. It is sometimes easier to delete databases when they become stale and simply create new ones as needed than to try to clean up the entries in a database.
To delete a database from the MongoDB shell, use the dropDatabase() method. For example, to delete the newDB database, you use the following commands to change to the newDB database and then delete it:
use newDBdb.dropDatabase()
You should be aware that dropDatabase() removes the current database, but it does not change the current database handle. This means if you drop ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access