对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

db.shutdownServer()(mongosh方法)

在版本5.0中进行了更改。

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() 采用以下语法:

db.shutdownServer({
force: <boolean>,
timeoutSecs: <int>
})

该方法采用以下字段:

字段
说明

可选。指定 true 以强制关闭 mongod 或 mongos。强制关闭会中断 mongod 或 mongos 上正在进行的任何操作,并可能导致意外行为。

You can pause and resume in-progress index builds using force. See db.shutdownServer() on Replica Set Members for more information.

可选。

从 MongoDB 5.0 开始,mongod 和 mongos 进入静默期,以允许所有正在进行的数据库操作在关闭之前完成。

如果一个 mongod 主节点收到关闭请求,则主节点:

  1. 尝试降级到从节点。

    如果降级失败,并且:

  2. 进入静默期。

  3. 结束所有剩余的数据库操作。

  4. 关闭。

对于 mongod 从节点或 mongos 关闭请求,在请求关闭之后进入静默期。

静止期由以下各项指定:

mongod 或 mongos 关闭时,客户端无法新建相关连接。

timeoutSecs specifies a time period in seconds. The default is:

  • 从 MongoDB 5.0 开始为 15 秒。

  • 在 MongoDB 5.0 以前的版本中为 10 秒。

mongod uses timeoutSecs as follows:

  • 如果当前节点是副本集的主节点,则 mongod 会等待 timeoutSecs 字段指定的秒数,以便可选举节点跟上,然后再降级主节点。有关追赶时间的详情,请参阅复制延迟。

  • If the current node is in the SECONDARY state after stepping down from being the primary, any remaining time specified in timeoutSecs is used for a quiesce period, which allows existing operations to complete. New operations are sent to other replica set nodes.

Starting in MongoDB 5.0, mongos uses timeoutSecs as a quiesce period, which allows existing operations to complete. New operations are sent to other mongos nodes. In MongoDB versions earlier than 5.0, mongos shuts down immediately and does not use timeoutSecs.

该操作为 shutdown 命令提供一个包装器。

此方法可用于以下环境中托管的部署:

重要

This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

For a mongod started with Authentication on Self-Managed Deployments, you must run db.shutdownServer() over an authenticated connection. See Access Control for more information.

For a mongod started without Authentication on Self-Managed Deployments, you must run db.shutdownServer() from a client connected to the localhost interface. For example, run mongosh with the --host "127.0.0.1" option on the same host machine as the mongod.

db.shutdownServer() fails if the mongod replica set member is running certain operations such as index builds. You can specify force: true to save index build progress to disk. The mongod recovers the index build when it restarts and continues from the saved checkpoint.

从 MongoDB 5.0 开始,mongod 和 mongos 进入静默期,以允许所有正在进行的数据库操作在关闭之前完成。

如果一个 mongod 主节点收到关闭请求,则主节点:

  1. 尝试降级到从节点。

    如果降级失败,并且:

  2. 进入静默期。

  3. 结束所有剩余的数据库操作。

  4. 关闭。

对于 mongod 从节点或 mongos 关闭请求,在请求关闭之后进入静默期。

静止期由以下各项指定:

mongod 或 mongos 关闭时,客户端无法新建相关连接。

timeoutSecs specifies a time period in seconds. The default is:

  • 从 MongoDB 5.0 开始为 15 秒。

  • 在 MongoDB 5.0 以前的版本中为 10 秒。

mongod uses timeoutSecs as follows:

  • 如果当前节点是副本集的主节点,则 mongod 会等待 timeoutSecs 字段指定的秒数,以便可选举节点跟上,然后再降级主节点。有关追赶时间的详情,请参阅复制延迟。

  • If the current node is in the SECONDARY state after stepping down from being the primary, any remaining time specified in timeoutSecs is used for a quiesce period, which allows existing operations to complete. New operations are sent to other replica set nodes.

Starting in MongoDB 5.0, mongos uses timeoutSecs as a quiesce period, which allows existing operations to complete. New operations are sent to other mongos nodes. In MongoDB versions earlier than 5.0, mongos shuts down immediately and does not use timeoutSecs.

警告

强制关闭主节点可能会导致所有尚未复制到从节点的写入操作发生回滚。

To run db.shutdownServer() on a mongod enforcing Authentication on Self-Managed Deployments, the authenticated user must have the db.shutdownServer() privilege. For example, a user with the built-in role hostManager has the appropriate permissions.

db.getSiblingDB("admin").shutdownServer()
db.getSiblingDB("admin").shutdownServer({ "force" : true })
db.getSiblingDB("admin").shutdownServer({ "timeoutSecs": 60 })
给本页内容打分