By default, shutting down Shell,mongodb stops running.
If you want to run in the background, you can start by simply adding the--fork function.
You can add--logappend after the log path to prevent the log from being deleted.
Copy Code code as follows:
Bin/mongodb--fork--dbpath=//--logpath=//--logappend
Run in the background, if you want to close it, you need to send him shutdownserver ()
1. General Order:
Copy Code code as follows:
$./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, in the 1.9.1 version will be followed by the following steps to close
Check data update time from MongoDB
If all the time difference between the MongoDB and the master is over 10, then the MongoDB is not closed (in which case we can configure Timeoutsecs to get the data updated from MongoDB).
If one of them has a time difference from the MongoDB to the main service in 10 seconds, the primary server shuts down and waits for the update to complete from the MongoDB and close.
3. If there is no up-to-date from MongoDB and you want to force off the service, you can add force:true by adding the following command:
Copy Code code as follows:
> Db.admincommand ({shutdown:1, force:true})
>//or
> Db.shutdownserver ({force:true})
4, specify a specific timeout time of the shutdown server, command ibid, plus a timeoutsec: parameter
Copy Code code as follows:
> Db.admincommand (shutdown:1, Force:true, Timeoutsec:5)
>//or
> Db.shutdownserver ({force:true, timeoutsec:5})