Create a MongoDB Database
To create a database in MongoDB use the “use” command.
Syntax
use database_name
Example
We have created a MongoDB database named gfgDB, as shown in the image below:
Here, we have created a database named as “gfgDB”. If the database doesn’t exist, MongoDB will create the database when you store any data to it.
Note: The "use" command is also used to switch to another database.
How to Create Database and Collection in MongoDB
MongoDB stores data records as documents that are stored together in collections and the database stores one or more collections of documents.
In this article, we will look at methods to create a database and collection in MongoDB.
Contact Us