How to Check if MongoDB Server Is Running
- Check if MongoDB Is Installed on Windows
- Check the MongoDB Version in Windows
- Check if MongoDB Is Running in Unix
- Check if MongoDB Is Installed in Ubuntu
- Check the MongoDB Version in Ubuntu
- Check if MongoDB Is Installed on Mac
- Check the MongoDB Version on Mac
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.
- Check if MongoDB is installed on Windows
- Check the MongoDB version on Windows
- Check if MongoDB is running in Unix
- Check if MongoDB is installed on Ubuntu
- Check the MongoDB version on Ubuntu
- Check MongoDB is installed on Mac
- 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
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.
-
Go to the
System Properties
, click on theEnvironment Variables
and click on the path in the system variable. -
Click on
new
and add the path of the MongoDB bin folder and click onOK
and save it. -
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
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.