- Reference >
mongo
Shell Methods >- Database Methods >
- db.dropDatabase()
db.dropDatabase()¶
On this page
Behavior¶
The db.dropDatabase()
wraps the dropDatabase
command.
Warning
This command obtains a global write lock and will block other operations until it has completed.
Changed in version 2.6: This command does not delete the
users associated with the current
database. To drop the associated users, run the
dropAllUsersFromDatabase
command in the database you are
deleting.
Warning
If you drop a database and create a new database with the same name, you
must either restart all mongos
instances, or use the
flushRouterConfig
command on all mongos
instances before reading or writing to that database. This action
ensures that the mongos
instances refresh their
metadata cache, including the location of the primary shard for the new database. Otherwise, the
mongos
may miss data on reads and may write data to a wrong shard.
Example¶
The following example in the mongo
shell uses the use
<database>
operation to switch the current database to the temp
database and then uses the db.dropDatabase()
method to drops
the temp
database:
See also