MongoDB tutorials


Learn MongoDB basics from our easy-to-follow tutorials.

Table of content:

  1. Download and Installation.
  2. Insert and read documents.
  3. Query document.
  4. Projected fields, limit, skip, and sort.
  5. Update, increment, and delete documents.
  6. Aggregation and group by clause.
  7. Indexing.
  8. Capped collections (automatically remove previous documents).
  9. Text search.
  10. Deployment (

1. Download and Installation

Video tutorial:

You can download MongoDB from their official site: and you need to select “Community server” if you are using it for localhost or small websites. For a very large company, I would recommend “Enterprise server”. Once downloaded, extract the zip file and you will see a folder named “mongodb”. Inside this folder, you will have another folder named “bin”.

Now open your terminal in that folder, you can use the following command:

cd "path to bin folder of mongodb"

Once you are inside the folder, you can start the MongoDB server using following command:


If that didn’t work, try simple:

mongodb start the server
mongodb start the server

Connect with MongoDB

Once your MongoDB server is started, you can open the database by opening a new command terminal. You can either open a new terminal window (window + n) or new tab (window + t).

window = cmd in Mac OS

And in terminal window or tab, run the following command (make sure the MongoDB server is running from previous command):


If that didn’t work, try simple:

mongodb connect database
connect database – MongoDB tutorials

Now you are in your database server. Here you can enter any MongoDB command to perform specific actions. By default, MongoDB server creates some databases for administrators and configurations. You can view all databases in the MongoDB server by running the following command:

show dbs
mongodb view all databases
mongodb view all databases

To create a database, you just need to use the “use” command. Use command will create a database if not exists, and open the database if already exists. For example, to create a database for users, run the following command:

use users

In all the tutorials of this MongoDB series, we will be using “users” collection.

Now if you run the command “show dbs“, you will NOT see your “users” database. This is because it will be displayed only when there is at-least one document in it.

We will know more about documents and collections and how to add them in the next tutorial.

How useful was this post

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post

Leave a Reply

Please disable your adblocker or whitelist this site!