对于 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 以强制关闭 mongodmongos。强制关闭会中断 mongodmongos 上正在进行的任何操作,并可能导致意外行为。

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

可选。

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

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

  1. 尝试降级到从节点。

    如果降级失败,并且:

  2. 进入静默期。

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

  4. 关闭。

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

静止期由以下各项指定:

mongodmongos 关闭时,客户端无法新建相关连接。

timeoutSecs指定了一个时间段(以秒为单位)。默认为:

  • 从 MongoDB 5.0 开始为 15 秒。

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

mongod 按如下方式使用 timeoutSecs

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

  • 如果当前节点在退出主节点后处于SECONDARY状态,则 timeoutSecs 中指定的任何剩余时间将作为静默期,以允许完成现有操作。新操作将发送到其他副本集节点。

从MongoDB5.0 开始,mongos 使用 timeoutSecs 作为静默期,以允许完成现有操作。新操作将发送到其他 节点。在.mongos 之前的MongoDB版本中,5 0mongos会立即关闭并且不使用 timeoutSecs。

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

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

重要

MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令

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 开始,mongodmongos 进入静默期,以允许所有正在进行的数据库操作在关闭之前完成。

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

  1. 尝试降级到从节点。

    如果降级失败,并且:

  2. 进入静默期。

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

  4. 关闭。

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

静止期由以下各项指定:

mongodmongos 关闭时,客户端无法新建相关连接。

timeoutSecs指定了一个时间段(以秒为单位)。默认为:

  • 从 MongoDB 5.0 开始为 15 秒。

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

mongod 按如下方式使用 timeoutSecs

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

  • 如果当前节点在退出主节点后处于SECONDARY状态,则 timeoutSecs 中指定的任何剩余时间将作为静默期,以允许完成现有操作。新操作将发送到其他副本集节点。

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 })
给本页内容打分