MongoDB is a popular NoSQL database that provides a flexible and scalable solution for managing and storing data. In this blog post, we will cover the basics of MongoDB and guide you through the installation process step by step.

What is MongoDB?

MongoDB is a document-oriented database that uses a flexible, JSON-like data model. Unlike traditional relational databases, MongoDB does not require a predefined schema, allowing for dynamic and easy handling of data. It is designed to handle large amounts of data and provide high availability and horizontal scalability.

Some key features of MongoDB include:

  • Document data model: MongoDB stores data in flexible, self-describing documents in JSON-like BSON format. Each document can have a different structure, allowing for easy schema evolution.
  • Scalability: MongoDB can scale horizontally across multiple servers and handle large datasets and high traffic loads.
  • Indexing: MongoDB supports various types of indexes, including single-field, multi-field, and geospatial indexes, to optimize query performance.
  • Rich query language: MongoDB provides a powerful query language with support for complex queries, aggregations, and geospatial queries.

Now that we have a brief understanding of MongoDB, let’s proceed with the installation process.

MongoDB Installation

To install MongoDB, follow these steps:

Step 1: Download MongoDB

  1. Visit the official MongoDB website at https://www.mongodb.com and navigate to the Downloads page.
  2. Choose the appropriate version of MongoDB for your operating system and download the installer.

Step 2: Run the Installer

  1. Locate the downloaded installer file and double-click on it to run the MongoDB installer.
  2. Follow the on-screen instructions to proceed with the installation. You can choose the installation directory and select additional components to install, such as MongoDB Compass, a graphical user interface for MongoDB.
  3. Once the installation is complete, make sure the option to start the MongoDB server automatically is selected.

Step 3: Add MongoDB Bin Directory to the System Path (Windows)

  1. Open the Start menu and search for “environment variables.”
  2. Click on “Edit the system environment variables.”
  3. In the System Properties window, click on the “Environment Variables” button.
  4. In the “System variables” section, locate the “Path” variable and click on “Edit.”
  5. Click on “New” and add the path to the MongoDB bin directory. By default, the bin directory is located at “C:\Program Files\MongoDB\Server\{version}\bin”.
  6. Click “OK” to save the changes.

Step 4: Verify the MongoDB Installation

  1. Open a new command prompt window.
  2. Run the following command to check if MongoDB is installed and configured correctly:
mongod --version
  • This command should display the installed MongoDB version.

Step 5: Create the MongoDB Data Directory

  1. Open the C drive in File Explorer.
  2. Create a new folder named “data”.
  3. Inside the “data” folder, create another folder named “db”. This is the default data directory used by MongoDB.

Step 6: Start the MongoDB Server

  1. In the command prompt, run the following command to start the MongoDB server:
mongod
  • If everything is set up correctly, the MongoDB server should start successfully without any errors.
  • Note: Keep the command prompt window running to keep the server active.

Step 7: Install MongoDB Shell (mongosh)

  1. Download the MongoDB shell (mongosh) separately from the official MongoDB website at https://www.mongodb.com/try/download/shell
  2. Extract the contents of the downloaded ZIP file.
  3. Move the extracted MongoDB shell folder to the MongoDB installation folder located in the C drive. By default, the installation folder is “C:\Program Files\MongoDB\Server\{version}”.
  4. Add the path to the MongoDB shell folder to the system environment variables, following the same steps mentioned in Step 3.

Step 8: Connect to the MongoDB Server with MongoDB Shell

  1. Open a new command prompt window.
  2. Run the following command to connect to the MongoDB server using MongoDB shell:
mongosh
  • The MongoDB shell should start and automatically connect to the running MongoDB server.
  • Note: Do not close the command prompt window running the MongoDB server (mongod) to maintain the connection between the server and the shell.

Congratulations! You have successfully installed MongoDB and connected to the MongoDB server using the MongoDB shell.

If you encounter any issues during the installation or have further questions, you can refer to my Stack Overflow answer here:

In this blog post, we covered the basics of MongoDB and provided a detailed installation guide. MongoDB offers a flexible and scalable solution for managing your data, and with the proper setup, you can start building applications that leverage the power of MongoDB.

Who Am I?

I’m Aswin Barath, a Software Engineering Nerd who loves building Web Applications, now sharing my knowledge through Blogging during the busy time of my freelancing work life. Here’s the link to all of my craziness categorized by platforms under one place: https://linktr.ee/AswinBarath

Thank you so much for reading my blog🙂.

Happy coding with MongoDB!


MongoDB Made Easy: Installation and Basics Unveiled was originally published in TechSoftware on Medium, where people are continuing the conversation by highlighting and responding to this story.

Categorized in:

Databases,

Last Update: 27 December 2023

Tagged in: