Delete Database in MongoDB

DropDatabase () method in MongoDB

The db.dropDatabase () command in MongoDB is used to delete an existing database.

Syntax

The basic syntax of the dropDatabase () command is as follows:

 db . dropDatabase () 

This command will delete the selected database. If you do not select any database, it will delete the default test database.

For example

First, check the list of available databases using the show dbs command.

 > show dbs local 0.78125GB mydb 0.23012GB test 0.23012GB > 

If you want to delete the new database mydb , then the dropDatabase () command will be as follows:

 > use mydb switched to db mydb > db . dropDatabase () >{ "dropped" : "mydb" , "ok" : 1 } > 

Now, try checking the list of databases.

 > show dbs local 0.78125GB test 0.23012GB > 

According to Tutorialspoint

Previous post: Create Database in MongoDB

Next article: Create Collection in MongoDB

5 ★ | 1 Vote

May be interested

  • Create Collection in MongoDBPhoto of Create Collection in MongoDB
    method db.createcollection (name, options) in mongodb is used to create collection.
  • Delete Collection in MongoDBPhoto of Delete Collection in MongoDB
    the db.collection.drop () method in mongodb is used to delete a collection from the database.
  • Data type in MongoDBPhoto of Data type in MongoDB
    mongodb supports many different data types. the following are some typical data types.
  • Insert Document in MongoDBPhoto of Insert Document in MongoDB
    to insert data into collection in mongodb, you need to use the insert () or save () method.
  • Query Document in MongoDBPhoto of Query Document in MongoDB
    to query data from collection in mongodb, you need to use the find () method in mongodb.
  • Update Document in MongoDBPhoto of Update Document in MongoDB
    the update () method updates the values ​​in the existing document while the save () method replaces the existing document with the transmitted document in that save () method.