MongoDB does not provide any interface or like MS SQL Server; using the “use” keyword, we can create a database in MongoDB. Like the RDBMS database, we do not need to already design a database or its table. See the following command.
>use myMongoDB
Result
switched to db myMongoDB
|
Command will create a new database if “myMongoDB” does not exist; otherwise, it will return the existing database. It means to switch at our database, we have to use the same DB command.
To check your currently selected database, use the below BD command.
>db
Result
myMongoDB
|
If you want to see, the lists of database use the following DB command.
>show dbs
Result
Test 0.078GB
admin (empty)
local 0.078GB
|
If you created a database and it does not contain any document, it will not show in lists, so we have to insert at least one document to see our created database in lists.
db.blog.insert({"title":"mongoDB tutorials"})
show dbs
Result
Test 0.078GB
admin (empty)
local 0.078GB
myMongoDB 0.078GB
|