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

replSetSyncFrom(数据库命令)

replSetSyncFrom

暂时覆盖当前mongod的默认同步目标。 此操作对于测试不同模式以及集成员未从所需主机复制的情况非常有用。

提示

In mongosh, this command can also be run through the rs.syncFrom() helper method.

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.

Run replSetSyncFrom in the admin database.

此命令可用于以下环境中托管的部署:

重要

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

该命令具有以下语法:

db.adminCommand(
{
replSetSyncFrom: "hostname<:port>"
}
)

该命令采用以下字段:

字段
类型
说明

replSetSyncFrom

字符串

该成员应从中进行复制的副本集成员的名称和端口号。 使用[hostname]:[port]表单。

副本集1 vote节点无法从0 votes节点同步。

For replSetSyncFrom to override the default sync target, settings.chainingAllowed must be set to true.

If settings.chainingAllowed is set to false, replSetSyncFrom returns ok:1 but does not set the sync target.

从MongoDB 5.0.2 开始,您可以通过将服务器参数 enableOverrideClusterChainingSetting 设置为 true 来覆盖 settings.chainingAllowed。即使 settings.chainingAllowedfalse,这也允许从辅助节点成员进行同步。

If an initial sync operation is in progress when you run replSetSyncFrom, replSetSyncFrom stops the in-progress initial sync and restarts the sync process with the new target.

仅根据需要修改默认同步逻辑,并且始终谨慎操作。

要同步的节点必须是数据集中数据的有效来源。如需从节点同步,节点必须:

  • 有数据。在启动或恢复模式下不能是仲裁节点,必须能够响应数据查询。

  • 可访问。

  • 在副本集配置中是同一集的成员。

  • 使用 members[n].buildIndexes 设置构建索引。

  • 集合中的另一个成员,以防止与自身同步。

如果尝试从落后当前节点 10 秒以上的节点复制,mongod 将记录警告,但仍会从落后的节点复制。另请参阅“复制延迟和流量控制”。

replSetSyncFrom provide a temporary override of default behavior. mongod will revert to the default sync behavior in the following situations:

  • mongod 实例将重新启动。

  • mongod 与同步目标之间的连接将关闭。

  • 如果同步目标落后副本集其他成员超过 maxSyncSourceLagSecs(默认30)秒。

For more information the use of replSetSyncFrom, see Configure a Self-Managed Secondary's Sync Target.

给本页内容打分