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
- Query analysis in MongoDBanalyzing queries is a very important aspect to assess the effectiveness of database and the effectiveness of the designed index. we will explore the two most frequently used queries, $ explain and $ hint.
- Text Search in MongoDBstarting with version 2.4, mongodb started supporting text indexes to search within the string content.
- How to use Aggregation Pipeline in MongoDBif you are using mongodb's mapreduce, it is best to switch to aggregation pipeline for more efficient computation.
- Instructions on 2 ways to install MongoDB on Raspberry Piin this tutorial, tipsmake will guide you through the process of installing and setting up the mongodb server software on your raspberry pi.
- Replica Set in MongoDBreplication is the process of synchronizing data from multiple servers. replication provides redundancy and increased data availability for multiple data copies on many different database servers. replication protects a database from the loss of a particular server. replication also allows you to recover data from hardware errors or service disconnections. with additional data copies, you can use it for recovery, reporting, or backup.
- Index (Mong) in MongoDBindex (index) supports the resolution of queries more efficiently. without an index, mongodb must scan through all a collection's document to select the documents that connect to the query command. this scan may be ineffective and requires mongodb to handle a large amount of data.
- How to save React form data in Mongo Databasetry adding mongodb to your web stack to see how easy it is to store and query form data!
- Create Backup in MongoDBto create a database backup in mongodb, you should use the mongodump command. this command will dump all server data into dump directory. there are many options available from which you can limit the amount of data or backup created by remote server.
- How to Build a GraphQL API with Apollo Server and MongoDBgraphql provides a flexible alternative to the classic rest approach when you are building apis.
- Data type in MongoDBmongodb supports many different data types. the following are some typical data types.