.
How to Create a Database in MongoDB?

How to Create a Database in MongoDB?

It is one of the most well-known NoSQL databases in use today. It’s an open-source document-oriented database that collects data in JSON-like format, making it easy to work with and highly scalable. One of the essential features of the database is the capability to create databases on the fly. In this blog, we will look at creating a database in MongoDB.

What is a MongoDB Database?

A MongoDB database is a container for a collection of documents. In other words, a database in MongoDB is a logical entity that stores a set of collections. These collections, in turn, store the documents that make up the data in the database. Each database in MongoDB is identified by a unique name.

Creating a MongoDB Database

Creating a database in it is an easy process. The first step is to connect to the MongoDB server. Once you have established a connection to the server, you can use the “use” command to create a new database. Here is an example of how to create a new database in MongoDB.

> use mydatabase

In the above example, “mydatabase” is the database name we want to create. If the database already exists, MongoDB will switch to it. If not, it will create a new database with the given name.

Checking the Created Database

You can use the “show dbs” command To verify that the database has been created. This command will display a list of all the databases in it’s server. Here is an example:

> show dbs

admin            0.000GB

config            0.000GB

local              0.000GB

mydatabase  0.000GB

In the above example, we can see that the “mydatabase” database has been created and has a size of 0.000GB.

Conclusion

Creating a database in MongoDB is an easy process that can be done using the “use” command. Once you have created a database, you can start adding collections to it and begin collecting your data.

MongoDB’s scalability and flexibility make it a best-suited database solution for modern applications. With the capability to create databases on the fly, developers can quickly adapt to changing requirements and add new functionality to their applications.

Share this article
Shareable URL
Prev Post

Calculated Columns vs Measures in Power BI: Understanding the Differences with Examples

Next Post

Steps to Configure Azure Front Door for an AKS Cluster

Read next