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
You should read it
May be interested
- Create Collection in MongoDBmethod db.createcollection (name, options) in mongodb is used to create collection.
- Delete Collection in MongoDBthe db.collection.drop () method in mongodb is used to delete a collection from the database.
- Data type in MongoDBmongodb supports many different data types. the following are some typical data types.
- Insert Document in MongoDBto insert data into collection in mongodb, you need to use the insert () or save () method.
- Query Document in MongoDBto query data from collection in mongodb, you need to use the find () method in mongodb.
- Update Document in MongoDBthe 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.