By default, shutting down the Shell,mongodb stops running.
If you want to run in the background, just add the--fork function when you start.
You can add--logappend after the log path to prevent the log from being deleted.
Bin/mongodb--fork--dbpath=//--logpath=//--logappend
Run in the background, if you want to close it, you need to send Shutdownserver ()
1. General Command: $ ./mongod> use admin> db.shutdownserver ()
Note that this command is only allowed locally, or a certified client.
2, if this is a master-slave replication cluster, after the 1.9.1 version will be followed by the following steps to close
- Check for data update time from MongoDB
- If all the time difference from MongoDB and master is more than 10, this will not close MongoDB (in this case, we can configure the Timeoutsecs way to let the data from MongoDB to complete the update)
- If there is a time difference from MongoDB to the primary service within 10 seconds, then the master server will shut down and wait for the update from MongoDB to complete and close.
3. If there is no up-to-date from MongoDB and you want to force shutdown service, you can add force:true by adding the command as follows:> Db.admincommand ({shutdown:1, force:true}) >//or > Db.shutdownserver ({force:true})
4, specify a specific time-out to shut down the server, the command above, plus a timeoutsec: Parameters > Db.admincommand (shutdown:1, Force:true, timeoutsec:5) >//or> db . Shutdownserver ({force:true, timeoutsec:5})
MongoDB Background Run