We have MongoDB 5.0.2 installed through Ubuntu 20.04 package manager (apt) and running as a systemd service (mongod.service). We would like to know which one of the below is the proper method to restart the mongo Instance in our scenario:
Thanks for the reply. So if I use the option 1 i.e. “db.shutdownServer()” command then does it stops the mongod service as well? Then can I start the DB by simply starting the mongod service? Please advise
You may run this command from any other machines, given the appropriate credentials, that can connect to the database. The database user issuing this command might not be able to restart mongod if he does not have access, as an OS user with sudo privileges, to the machine where mongod is running.
This can be done by any OS admin that has access with sudo privileges to the machine where mongod is running. This OS user will also be able to start mongod.
So depending of the security model you have. A DB user can terminate mongod using shutdownServer and only an OS user can start/restart it. The same person may have both DB user and OS user credentials.
Hi there, @steevej My ultimate goal is to reboot the MongoDB server. For that, I want to shutdown the MongoDB gracefully followed by the Server reboot and then start the MongoDB Instance.
So what I understand from the responses is, if I shutdown using “db.shutdownServer()” command the DB instance will stop gracefully. However the service “mongod.service” will only shutdown if the DB User has the privilege on the OS User. Please correct me if I am wrong!
While my understanding is that the DB users has no relation with the OS user. Their scope is limited to the Database only. The OS service “mongod.service” is owned by “mongodb” OS user which is also the owner of MogoDB file structure at OS Level.
So in short, if I stop MongoDB by “db.shutdownServer()” command using a user that has dbAdmin privilege on admin database, then it should in turn trigger “Mongodb” OS user to stop the service as well. After rebooting the machine, the MongoDB should directly start once the OS Service “mongod.service” is started.