The db.dropDatabase() command is used to drop the current database and associated data files to that database. The db.dropDatabase() wraps the dropDatabase command.
> db.dropDatabase()
Note: This command will delete the selected database. If you haven't selected any database, then it will delete the test database, which is default database.
Example:
If you want to delete the existing database <mytestdb>, then db.dropDatabase() command will be as follows:
> use mytestdb
switched to db mytestdb
> db.dropDatabase()
{"dropped" : "mytestdb", "ok" : 1} (If there is data in Database)
or
{"ok" : 1} (If there is no data in Database)
Syntax:
> use mytestdb
switched to db mytestdb
> db.runCommand({dropDatabase : 1})
{"dropped" : "mytestdb", "ok" : 1} (If there is data in Database)
or
{"ok" : 1} (If there is no data in Database)
Note: This command obtains a global write lock, so it will all other operations until it has completed.
Syntax:
Basic syntax of db.dropDatabase() command is:> db.dropDatabase()
Note: This command will delete the selected database. If you haven't selected any database, then it will delete the test database, which is default database.
Example:
If you want to delete the existing database <mytestdb>, then db.dropDatabase() command will be as follows:
> use mytestdb
switched to db mytestdb
> db.dropDatabase()
{"dropped" : "mytestdb", "ok" : 1} (If there is data in Database)
or
{"ok" : 1} (If there is no data in Database)
You can also drop database using dropDatabase command:
Syntax:
> use mytestdb
switched to db mytestdb
> db.runCommand({dropDatabase : 1})
{"dropped" : "mytestdb", "ok" : 1} (If there is data in Database)
or
{"ok" : 1} (If there is no data in Database)
Note: This command obtains a global write lock, so it will all other operations until it has completed.
No comments:
Post a Comment