How to Check if MongoDB Server Is Running

Tahseen Tauseef Feb 02, 2024
  1. Check if MongoDB Is Installed on Windows
  2. Check the MongoDB Version in Windows
  3. Check if MongoDB Is Running in Unix
  4. Check if MongoDB Is Installed in Ubuntu
  5. Check the MongoDB Version in Ubuntu
  6. Check if MongoDB Is Installed on Mac
  7. Check the MongoDB Version on Mac
How to Check if MongoDB Server Is Running

In this MongoDB tutorial, you will learn how to determine whether MongoDB is installed and how to get the MongoDB version. We’ll also go through how to do this task on different operating systems.

The following are the subjects that will be addressed in this tutorial.

  1. Check if MongoDB is installed on Windows
  2. Check the MongoDB version on Windows
  3. Check if MongoDB is running in Unix
  4. Check if MongoDB is installed on Ubuntu
  5. Check the MongoDB version on Ubuntu
  6. Check MongoDB is installed on Mac
  7. Check the MongoDB version on Mac

Check if MongoDB Is Installed on Windows

To determine whether or not MongoDB is installed, perform the steps outlined below.

  • Open command prompt
  • Go to the mongod.exe file in the bin folder.
    C:\Program Files\MongoDB\Server\4.0\bin>
    
  • Now, start the MongoDB server using the mongo command.
    C:\Program Files\MongoDB\Server\4.0\bin>mongo
    

mongo command

As you can see, the MongoDB server is up and running, indicating that MongoDB is installed on your machine.

Please keep in mind that occasionally issues occur while starting the server since we haven’t provided the path; thus, you must manually specify the path in the environment variable.

Examine the environment variable. If it hasn’t already been set, specify the route and restart the server.

If you wish to set the route in your system, do the following.

  1. Go to the System Properties, click on the Environment Variables and click on the path in the system variable.

  2. Click on new and add the path of the MongoDB bin folder and click on OK and save it.

    Environment Variables

  3. You successfully set the path of MongoDB.

Check the MongoDB Version in Windows

You may verify the version of MongoDB in Windows by using the following command.

C:\Program Files\MongoDB\Server\4.0\bin>mongod --version

check version

This allows you to check the MongoDB version. We are currently running MongoDB version 5.0.2.

Check if MongoDB Is Running in Unix

Check with either:

ps -edaf | grep mongo | grep -v grep  # "ps" flags may differ on your OS

or

/etc/init.d/mongodb status
# for MongoDB version < 4.1

/etc/init.d/mongod status
    # for MongoDB version >= 4.1

or

service mongodb status         # for MongoDB version < 2.6

service mongod status          # for MongoDB version >= 2.6

To test if mongod is running (you must root or prefix everything with sudo). Remember that the grep command will always appear as a distinct process.

It has been discovered that the query below is much more consistent. The value returned can count the number of instances of mongod running.

ps -ax | grep mongo

Check if MongoDB Is Installed in Ubuntu

Use the following commands to determine whether or not MongoDB is installed on Ubuntu.

Start the MongoDB server.

$ sudo service mongod start

If it is not already running, you may use this to start the MongoDB server in Ubuntu. If this returns an error, you must first install MongoDB on your PC.

Check the status of the MongoDB server is running or not.

$ sudo service mongod status

With this command, you can determine if MongoDB is running or not. If it is not already running, you must first install MongoDB on your machine.

Check the MongoDB Version in Ubuntu

In MongoDB, use the following command to determine the version of MongoDB in Ubuntu.

$ mongod --version

You may use this command to verify the version of MongoDB in Ubuntu.

Check if MongoDB Is Installed on Mac

Use the following commands to see if MongoDB is installed on your Mac.

ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '

This command displays the number of MongoDB processes that are currently active. If it is more than zero, your machine is running MongoDB.

Start the MongoDB server using the following command.

mongod

This command starts the MongoDB server; if it succeeds, MongoDB is already installed on your system; otherwise, you must first install it.

Check the MongoDB Version on Mac

You may verify the version of MongoDB on Mac using the following command.

mongod --version

You may use this command to check the version of MongoDB on your Mac.