Creating a Database Using MongoDB

MongoDB is one of the most sought-after NoSQL databases. The open-source cloud platform has helped thousands of developers and data scientists manage large volumes of data with JSON documents and flexible schemas.


And according to VentureBeat’s cloud revenue growth report, MongoDB is a significant contributor to overall cloud revenue.

So if you haven’t learned how to build a database on MongoDB yet, you’re missing out. The company recorded 39,100 customers in its latest quarterly report, as covered by CNBC.

Fortunately, you can soon be one of them once you are done with this tutorial. Read on to find out how to create a database in MongoDB. For clarity purposes, this guide will focus on MongoDB Atlas UI.

Create an Account

First, you’ll need to register an account on MongoDB Atlas with either your email address, Google account, or GitHub account. You’ll also be prompted to read the terms and service when doing so. Don’t worry; signing up is free!

Deploy a Cluster

After logging in, you will be prompted to build a cluster. In MongoDB’s terms, a cluster is a replica set. Atlas offers free clusters (M0) as a small-scale development environment to host your data. They’re free and provide access to basic Atlas features.

If you choose to deploy M0 clusters, you’ll have to pick your cloud provider and region. M0 clusters are supported on Amazon Web Services, Microsoft Azure, and Google Cloud Platform.

Enter a name for your cluster and then click “Create Cluster”.

Create a Database User

To access your cluster, you’ll need to create a database user. Go to Connect > Databases > Databases Deployment and click “Connect” on the cluster. This will prompt you to add your IP address.

Once IP address is added, you can set a name and password. Fill these in, then click “Create Database User.

Connect to Your Cluster

You can connect to your cluster in various ways. For this tutorial, we will cover how to connect via MongoDB Shell (mongosh). You will need to have it installed on your machine before you start.

Once installed, navigate to Connect > Databases > Database Deployments and then click “Connect.” Then click “Choose a connection method” and “Connect with the MongoDB Shell.” Select your version of MongoDB Shell from the dropdown menu, then copy and pase the provided connection string into your terminal.

Insert and View a Document

Run the command below on mongosh. This will create a database called “gettingStarted” and will point your environment to it. 

use gettingStarted

Next, insert a document to your database using the following command. This will create a new collection called “People” and insert a document there.

  name: { first: 'Alan', last: 'Turing' },
  birth: new Date('Jun 23, 1912'),
  death: new Date('Jun 07, 1954'),
  contribs: [ 'Turing machine', 'Turing test', 'Turingery' ],
  views : Long(1250000)

You will receive confirmation once you’ve successfully inserted a document into the collection.

Load Sample Data

For this step, we can use the Atlas UI again. Just navigate to Database Deployments > Database. Then open the “Load Sample Dataset” dialog.

Go to your database and click the (…) button. Then click “Load Sample Dataset.” You can view your sample data by clicking the database deployment’s “Browse Collections” button.


That’s it! You successfully created a database in MongoDB. The steps will vary depending on the drivers you use.

If you’re interested, MongoDB University launched a new curriculum to help close the tech skills gap. It includes new courses and certifications, plus multiple Atlas labs that provide hands-on access to the product.

For more database-related tutorials, check out how to log WordPress database queries to file.

Hello, I am Guest Author. Thank you for reading!

This entry was submitted by a guest author. If you wish to contribute, please contact me for my terms.

Divi WordPress Theme - My Review

Divi WordPress Theme
Divi is a WordPress theme that web designers do not want you to know. It comes with a drag-and-drop theme builder. You can build beautiful looking unique websites without touching a line of code. Just choose from one of the many pre-made layouts, or pick elements and arrange them any way you like.

Divi is every WordPress developer's wet dream. Surprise your clients with neat responsive websites and have fun building them.

Divi comes from Elegant Themes. If you enjoy building websites, you *need* an Elegant Themes membership. 87 beautiful themes and 5 plugins for the cost of less than a candy-bar each!

Note: I am an avid user of Divi myself and this is a honest review. I wouldn't recommend something that I do not personally find amazing.

Leave a Reply

Your email address will not be published. Required fields are marked *