Can I restart mongodb server through mongo shell?
Asked Answered
R

2

8

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

Resonant answered 13/3, 2018 at 13:34 Comment(0)
B
4

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.

Bigley answered 13/3, 2018 at 14:7 Comment(0)
R
1

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.

Rodgerrodgers answered 13/3, 2018 at 13:46 Comment(1)
Ok, got it. Use: mongo --host <hostname> --port <port> --username <username> --password <password> -> use admin -> db.shutdownServer()Rodgerrodgers

© 2022 - 2024 — McMap. All rights reserved.