Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I restart mongodb server through mongo shell?

Can I restart a MongoDB server through the mongo CLI client?

like image 865
Cracken Avatar asked Mar 13 '18 13:03

Cracken


2 Answers

You can't stop and start (restart) it from the client. As i.kimiko already mentioned, you can shut it down on your client with db.shutdownServer() through a mongo shell database methods documentation 3.6.0 But then you'd still have to connect to the server and restart it from there with sudo service mongodb start for example.

like image 92
Alex P. Avatar answered Sep 23 '22 20:09

Alex P.


You can shutdown server via client.

mongo --host "hostname where server or IP" --port "port of mondodb server" --username "username" --password "password"
use admin
db.shutdownServer()

link to documentation about db.shutdownServer() mongodb 3.6.0
After that you may up that server via other service\tool (from a host machine when a mongodb server installed), like cron for example or using systemd unit.

like image 35
i.kimiko Avatar answered Sep 20 '22 20:09

i.kimiko