How to stop and start MongoDB Server

In this article, we will see how to stop and start MongoDB Server on Linux and Windows Operating Systems. We have different ways to stop MongoDB server. First we will see the methods to stop MongoDB Server.

How to Stop MongoDB Server on Linux and Windows Servers:

a). How to stop MongoDB on Linux:


1) Shutdown from Mongo Shell on Linux: We must issue the shutdown command against the admin database

use admin db.shutdownServer()

How to stop and start MongoDB Server

2) Shutdown MongoDB server from services.

systemctl stop mongod.service

3) By using conf file.

sudo sudo mongod -f /etc/mongod.conf --shutdown

4) By killing Linux process ID:
command on Linux shell:

ps -edaf | grep mongo | grep -v grep

Output:

root@mongodb2:~# ps -edaf | grep mongo | grep -v grep avahi 696 1 0 10:10 ? 00:00:00 avahi-daemon: running [mongodb2.local] mongodb 2409 1 21 10:57 ? 00:00:01 /usr/bin/mongod --config /etc/mongod.conf

kill 2409

5) Running from Linux shell with mongo command.
Run either of below ones

mongo admin --eval "db.shutdownServer()"

or

mongo --eval "db.getSiblingDB('admin').shutdownServer();quit()"

Output:

root@mongodb2:~# mongo --eval "db.getSiblingDB('admin').shutdownServer();quit()" MongoDB shell version v4.2.1 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("9fa6ca5a-df92-433c-b15c-00ce9a4df2c5") } MongoDB server version: 4.2.1 2019-11-16T10:59:38.348-0800 I NETWORK [js] DBClientConnection failed to receive message from 127.0.0.1:27017 - HostUnreachable: Connection closed by peer server should be down... root@mongodb2:~#

b). How to stop MongoDB on Windows:

1) Open the command prompt as administrator and execute below command.
net stop MongoDB
or
2)goto services.msc Then scroll down until MongoDB Server. Right click on it select Stop.

How to Start MongoDB Server on Linux and Windows Servers:

a). How to start MongoDB on Linux:
Use any of these commands to start MongoDB Server on Linux

systemctl start mongod.service service mongod start sudo systemctl start mongod.service sudo service mongod start

strong class=”strong”>b). How to start MongoDB on Windows:

1) Open the command prompt as administrator and execute below command.
net start MongoDB
or
2)goto services.msc Then scroll down until MongoDB Server. Right click on it select Start.

How to check MongoDB Server status on Linux and Windows Servers:

On Linux:

systemctl tatus mongod.service service mongod tatuss sudo systemctl status mongod.service sudo service mongod status

So in this article, we have explained different methods to stop and start the MongoDB on Linux and Windows operating Systems.

Leave a Reply

Your email address will not be published. Required fields are marked *