Skip to main content

Running MongoDB Server

MongoDB is a widely used, highly-scalable NoSQL database that provides high performance, high availability and easy scalability. In this tutorial, we will go through the process of setting up and running a MongoDB server.

Step 1: Download MongoDB

The first step to run MongoDB on your computer is to download it. Visit the MongoDB official website to download the appropriate version for your operating system.

https://www.mongodb.com/try/download/community

Choose the version that's right for your OS, download the installer and proceed with the installation.

Step 2: Install MongoDB

After downloading the MongoDB installer, proceed with the installation process. The installation is pretty straightforward. Just follow the prompts on the screen and choose the default settings.

Step 3: Set up MongoDB Environment

Once the installation is complete, you need to add MongoDB's bin folder to the system's PATH environment variable. This allows you to access MongoDB's commands from anywhere on your system.

On Windows, the MongoDB's bin folder is usually located at C:\Program Files\MongoDB\Server\{VERSION}\bin. Here, {VERSION} is the version of MongoDB you installed.

To add this to PATH:

  • Open System Properties (Right click on Computer > Properties > Advanced system settings)

  • Click on Environment Variables

  • Under System Variables, find PATH and click on Edit

  • In the Variable value field, append the path of MongoDB's bin folder. Make sure to separate this path from the existing paths by a semicolon (;).

On Linux, you can add the MongoDB bin directory to the PATH variable by using the following command:

export PATH=<mongodb-install-directory>/bin:$PATH

Step 4: Run MongoDB Server

To start the MongoDB server, open your terminal or command prompt and type the following command:

mongod

This will start the MongoDB server and by default, MongoDB will start running on port 27017.

Step 5: Connect to MongoDB

To interact with MongoDB, you need to use the MongoDB shell, mongo. Open a new terminal or command prompt window and type the following command:

mongo

This will connect to your MongoDB server and you will see an output like this:

MongoDB shell version: x.x.x
connecting to: test
>

Congratulations! You have successfully set up and started your MongoDB server. You can now start creating, reading, updating, and deleting data in your MongoDB server.

Conclusion

In this tutorial, we’ve covered the basics of setting up and running a MongoDB server. The process involves downloading and installing MongoDB, setting up the MongoDB environment, running the MongoDB server, and connecting to MongoDB. With your server now running, you’re ready to start exploring MongoDB and its features.