What is NoSQL MongoDB

MongoDB is an open-source document database and a leading NoSQL database. MongoDB is a cross-platform, document-oriented database that provides high performance, high availability, and easy scalability.

MongoDB works on the concept of collection and documentation. It is not a Relational Database like MySQL or Oracle. In MySQL database, there is a Database, then Tables, and then Columns.

MongoDB structure is like a Database, then Collections, and then Documents. So there is no concept like Tables and Columns in MongoDB. Nevertheless, the MongoDB database is vastly popular with the Node.js platform. 


First, we learn the basic structure of the MongoDB database, like what is collections and what is a document. Then we will install MongoDB on Mac System and then play with it.


A collection is a group of MongoDB documents. It is the equivalent of a Relational Database table. A collection exists within a single database.


The document is a set of key-value pairs. Documents have a dynamic schema. Dynamic schema means that documents in the same collection do not need the same fields or structure, and standard fields in a collection’s documents may hold different data types.

Example of Document

	"_id" : ObjectId("5ac0ac19d412d208b8c91214"),
	"course_name" : "react.js",
	"course_price" : 10,
	"__v" : 0

It is like a JSON Object. The document contains key-value pairs. Here, _id is generated by MongoDB. It is equivalent to id in MySQL database; the values are different because, in most cases in MySQL, id is an incremental field starting from 1.

Install MongoDB on Mac.

If you have installed the MongoDB database on Mac, skip this step. For newbies, go to your terminal and hit the following command to install Homebrew. If you have installed it, then do not type this command.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Next, add Homebrew’s location to your $PATH  in your .bash_profile or .zshrc file.

export PATH="/usr/local/bin:$PATH"

Now, install MongoDB using Homebrew.

Type the following command in your terminal.

brew install mongodb

After downloading Mongo, create the “db” directory. This is where the Mongo data files will live. You can make the directory in the default location by running mkdir -p /data/db

Make sure that the /data/db directory has the right permissions by running the following command.

sudo chown -R `id -un` /data/db

Run the Mongo daemon in one of your terminal windows run mongod. It should start the Mongo server at port number 27017.


Install MongoDB on Mac

Now, your MongoDB server is ready to connect any web application. Once you are connected, you can see that one connection has been added.

While working on Any web project that uses the MongoDB database, you need to open this connection and never close the terminal.

Otherwise, the connection between a web application and a database will be lost. So never down the mongo server.

MongoShell Interface

Mongo is an interactive JavaScript shell interface to MongoDB, which provides a powerful interface for systems administrators and developers to test queries and operations directly with the database. 

Now, we can use the following command to see how many databases are there by default.

show dbs

MongoDB Database Example

Create Database.

Now, we can create one database using the following command.

use demodb

If the database is not there, then it will create for us. If already there, then it switches to that database.

To check your currently selected database, use the following command.


MongoDB Tutorial

Create Collection.

The cool thing about MongoDB is that you need not create a collection before inserting the document. Instead, add a document to the collection with a single command, and MongoDB creates that collection on the fly.

db.person.insert({name: 'mahavir', age: 70})

It will create a collection called the person and add one document.

So, you can see the inserted documents using the following command.


For a prettier result, we can query like this.


Beginners guide to up and running with MongoDB

Shell Help

To see the list of help in the mongo shell, type the following.


It will list the commands. You can use it to find help in database administration, query the results, etc.

mongodb help

Now, let us say we need help to find all the documents in the person collection. Then we can go through help to execute the right query.

From starting, first, check whether you are in the correct database or not. So first, switch to the correct database.

use demodb

Then, check whether you are in the collection or not.


If not, then switch to the proper collection using the following command.

use person

Now, type the following code to get all the methods applicable to any collection.


Database collection help

Now, you can apply the first command to return all the documents. But you can go further for help. Type the following command.


So, you will see what other methods you can chain with the find() method to get the desired result.

MongoDB NoSQL Database Tutorial

You can also drop the database using the following command.


We will dive deep into the NoSQL MongoDB database in future posts. That is it for now; NoSQL MongoDB Tutorial is over.

Thanks for taking it.

2 thoughts on “What is NoSQL MongoDB”

  1. Thank you, this website is great. I am learning how to connect React with Backend and your last tutorial about it was very powerful.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.