On this page本页内容
db.
shutdownServer
()¶Shuts down the current mongod
or mongos
process cleanly and safely. You must issue the db.shutdownServer()
operation against the admin database.
db.shutdownServer()
has the following syntax:语法如下所示:
The method takes the following optional field:
force | Optional. Specify |
timeoutSecs | Optional. The number of seconds the primary should wait for a secondary to catch up. Defaults to If no secondaries catch up within the specified time, the command fails. |
This operation provides a wrapper around the shutdown
command.
For a mongod
started with Authentication, you must run db.shutdownServer()
over an authenticated connection. See Access Control for more information.
For a mongod
started without Authentication, you must run db.shutdownServer()
from a client connected to the localhost interface. For example, run a mongo
with the --host "127.0.0.1"
option on the same host machine as the mongod
.
db.shutdownServer()
on Replica Set Members¶db.shutdownServer()
fails if the mongod
replica set member is running certain operations such as index builds. You can specify force: true to force the member to interrupt those operations and shut down.
If running db.shutdownServer()
against the replica set primary, the operation implicitly uses replSetStepDown
to step down the primary before shutting down the mongod
. If no secondary in the replica set can catch up to the primary within 10
seconds, the shutdown operation fails. You can issue shutdownServer()
with force: true to shut down the primary even if the step down fails.
Warning
Force shutdown of the primary can result in the rollback of any writes not yet replicated to a secondary.
To run db.shutdownServer()
on a mongod
enforcing Authentication, the authenticated user must have the db.shutdownServer()
privilege. For example, a user with the built-in role hostManager
has the appropriate permissions.