On this page本页内容
Changed in version 5.0.在版本5.0中更改。
db.shutdownServer()
Shuts down the current 清洁安全地关闭当前mongod or mongos process cleanly and safely. mongod或mongos进程。You must issue the 必须对db.shutdownServer() operation against the admin database.admin数据库执行db.shutdownServer()操作。
db.shutdownServer() has this syntax:具有以下语法:
db.shutdownServer({
force: <boolean>,
timeoutSecs: <int>
})
The method takes these fields:该方法采用以下字段:
| force |
|
| timeoutSecs |
|
This operation provides a wrapper around the 此操作提供shutdown command.shutdown命令的包装。
For a 对于以mongod started with Authentication, you must run db.shutdownServer() over an authenticated connection. Authentication启动的mongod,必须在经过身份验证的连接上运行db.shutdownServer()。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. mongod,必须从连接到localhost接口的客户端运行db.shutdownServer()。For example, run 例如,在与mongosh with the --host "127.0.0.1" option on the same host machine as the mongod.mongod相同的主机上使用--host "127.0.0.1"选项运行mongosh。
db.shutdownServer()如果db.shutdownServer() fails if the mongod replica set member is running certain operations such as index builds. mongod副本集成员正在运行某些操作(如索引构建),db.shutdownServer()将失败。You can specify force: true to force the member to interrupt those operations and shut down.您可以指定force:true来强制成员中断这些操作并关闭。
mongosmongosStarting in MongoDB 5.0, 从MongoDB 5.0开始,mongod and mongos enter a quiesce period to allow any ongoing database operations to complete before shutting down.mongod和mongos进入静默期,以便在关闭之前完成任何正在进行的数据库操作。
If a 如果mongod primary receives a shut down request, the primary:mongodprimary收到关闭请求,则primary:
Attempts to step down to a secondary.尝试降级到次要级别。
If the step down fails and a:如果步降失败,并且:
shutdown or db.shutdownServer() command was run, mongod only continues the shut down steps if the force field is true, or ashutdown或db.shutdownServer()命令已运行,mongod仅在force字段为true或以下情况时继续关闭步骤:SIGTERM signal was sent to mongod, mongod always continues the shut down steps.SIGTERM信号被发送到mongod,mongod总是继续关闭步骤。For a 对于mongod secondary or mongos shut down request, the quiesce period is entered after a shut down was requested.mongod secondary或mongos关闭请求,在请求关闭后进入静默期。
The quiesce period is specified by the:静止期由以下参数指定:
shutdown or db.shutdownServer() command was run, ortimeoutSecs字段(如果运行了shutdown或db.shutdownServer()命令),或shutdownTimeoutMillisForSignaledShutdown server parameter if a SIGTERM signal was sent to mongod, orshutdownTimeoutMillisForSignaledShutdown服务器参数(如果SIGTERM信号发送到mongod),或mongosShutdownTimeoutMillisForSignaledShutdown server parameter if a SIGTERM signal was sent to mongos.mongosShutdownTimeoutMillisForSignaledShutdown服务器参数,如果SIGTERM信号被发送到mongos。The timeoutSecs field defaults to 在MongoDB 5.0中,15 seconds in MongoDB 5.0.timeoutSecs字段默认为15秒。
Clients cannot open new connections to a 客户端无法打开与正在关闭的mongod or mongos that is shutting down.mongod或mongos的新连接。
In MongoDB 4.4 and earlier, if running 在MongoDB 4.4及更早版本中,如果对副本集主服务器运行db.shutdownServer() against the replica set primary, the operation implicitly uses replSetStepDown to step down the primary before shutting down the mongod. db.shutdownServer(),则操作会在关闭mongod之前隐式使用replSetStepDown逐步关闭主服务器。If no secondary in the replica set can catch up to the primary within 如果复制集中没有辅助设备可以在10 seconds, the shutdown operation fails. 10秒内赶上主设备,则关闭操作将失败。You can issue 您可以使用db.shutdownServer() with force: true to shut down the primary even ifthe step down fails.force:true命令db.shutdownServer()来关闭主服务器,即使步降失败。
To run 要在强制身份验证的db.shutdownServer() on a mongod enforcing Authentication, the authenticated user must have the db.shutdownServer() privilege. mongod上运行db.shutdownServer(),经过身份验证的用户必须具有db.shutdownServer()权限。For example, a user with the built-in role 例如,具有内置角色hostManager has the appropriate permissions.hostManager的用户具有相应的权限。
mongoddb.getSiblingDB("admin").shutdownServer()
mongoddb.getSiblingDB("admin").shutdownServer({ "force" : true })
mongod With Longer Timeoutmongoddb.getSiblingDB("admin").shutdownServer({ "timeoutSecs": 60 })