0

How To Create and Drop a database in MongoDB

I have created a database,but when i am listing the database,i could not find the database name that i have created.So may i know the procedure to create and drop the database.

Mongodb Add a comment
otwol
asked Aug 13 2019

Answer

0

Create a database in MongoDB,run the following commands

 > use  -new database name- 
 > show dbs  (  which lists the databases available in the MongoDB and also to  check the newly created database name)

As it Hasn't showed up the database you have created,just insert a document into the newly created database ,to do that run the command

    > db.users.insert({"id":1})

Now check the available databases in the MongoDB, which will show up the newly created database in the available database list of mongoDB

> show dbs

To drop the database

> use databasename;
> db.dropdatabase()

The above command drops the switched in database

Add a comment
linuxhelp
asked Aug 14 2019
edited Aug 20 2019
Post your Answer