How to create database in MongoDB

by Ismail.EL
0 comment


How to create database in MongoDB

In this guide, we will show you how and when MongoDB will create the database and collections.

1. Show all database

Issue “show dbs” to display all available databases.

2. Define a database name

“use DATABASE_NAME” is used to create database.
The command will create a new database, if it doesn’t exist otherwise it will return the existing database.
Basic syntax of use DATABASE statement is as follows:

Example:
Here we will create a database with name <devopsteampaceDB>:

To check your currently selected database use the command “db”:

If you want to check your databases list, then use the command show dbs.

database devopsteampaceDB has been created but is not present in list.
then we must create save database:

3. Save a database:

4. Conclusion

In this post, i have explained How to create database in MongoDB.
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂

21070cookie-checkHow to create database in MongoDB

Related Posts

Leave a Comment