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

将托管集群连接到 Atlas

mongosync 实用程序在MongoDB集群之间创建连接。mongosync 可以连接到以下任何集群:

本页提供了使用MongoDB Mongosync 将自管理集群连接到Atlas 集群的说明。

有关连接 Atlas 集群的更多详细信息,请参阅连接数据库部署

注意

为获得最佳性能,请在迁移之前将自我管理集群升级到最新的MongoDB Server补丁发布。 有关更多信息,请参阅升级到MongoDB的最新自我管理补丁版本。

mongosync 使用MongoDB URI 连接string连接自管理集群:

  • SRV 连接方案的形式为:

    mongodb+srv://[username:password@][host.domain.TLD][/defaultauthdb][?options]
  • 标准 URI 连接方案的形式如下:

    mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]

Specify the hostnames of the mongod instances the same way that they are listed in your replica set configuration.

For sharded clusters, specify the hostnames of the mongos instances instead of the mongod instances.

注意

mongosync does not require the replicaSet option.

mongosync 使用MongoDB URI 连接string连接Atlas集群:

  • SRV 连接方案的形式为:

    mongodb+srv://[username:password]@[clusterName].[host].mongodb.net/

    有关如何在 中查找 SRV 连接string Atlas的信息,请参阅 连接到集群。

  • 标准 URI 连接方案的形式如下:

    mongodb://[username:password]@[clusterName].[host].mongodb.net/

mongosync requires the primary read preference to connect to the source and destination clusters. For more information, see Read Preference Options.

提供有效的身份验证以连接到MongoDB Atlas集群。 如果您还没有Atlas数据库用户,则必须创建一个用户。

如果源集群或目标集群需要身份验证,则必须在调用mongosync时提供正确的档案。

mongosync连接字符串中指定的用户必须对源集群和目标集群具有所需的权限。权限因您的环境以及您是否要使用反向同步而异。

源集群的自我管理权限为:

有关服务器角色的详细信息,请参阅:自管理部署中基于角色的访问控制。

To update user permissions, see: grantRolesToUser.

目标集群的Atlas权限为:

同步类型
所需的目标权限

默认

双重写入阻塞、反转或多重反转

有关Atlas角色的详细信息,请参阅Atlas用户角色。

要更新Atlas user权限,请参阅:管理对项目的访问权限。

The mongosync utility can be hosted on its own hardware close to either the source or destination cluster. It does not have to be hosted on the same server as one of the mongod or mongos instances in the cluster. This flexibility allows you to push, or pull, data to the destination cluster with minimal impact on the mongod or mongos instances running there.

mongosync连接时,它处于IDLE状态。 您必须发出启动命令才能开始同步。

Before you attempt to run mongosync with an M10+ Atlas cluster, disable the Require Indexes for All Queries option to set notablescan to false on both the source and destination clusters.

源集群cluster0托管在以下服务器和端口上:

  • clusterOne01.fancyCorp.com:20020

  • clusterOne02.fancyCorp.com:20020

  • clusterOne03.fancyCorp.com:20020

目标 Atlas 集群cluster1托管在以下服务器和端口上:

  • cluster2Name-01.abc123.com:27017

  • cluster2Name-02.abc123.com:27017

  • cluster2Name-03.abc123.com:27017

每个集群上都配置了一个管理用户clusterAdmin ,密码为superSecret

自管理集群的通用连接string格式为:

mongodb://<user>:<password>@<ip-address>:<port>,<ip-address>:<port>,<ip-address>:<port>

集群的通用连接string Atlas格式为:

mongodb://<user>:<password>@<clusterName>.<hostname>.mongodb.net/

使用您收集的自管理集群的连接信息为cluster0创建连接字符串:

cluster0:
mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020

您可以从string 用户界面获取Atlas 集群的连接Atlas 。要学习;了解详情,请参阅连接到数据库部署。

下面的mongosync命令布局已修改以进行显示。 要使用mongosynccluster0连接到cluster1 ,请在一行中输入以下命令:

mongosync \
--cluster0 "mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020" \
--cluster1 "mongodb://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net"

Atlas clusters require TLS connections. To use mongosync with Atlas clusters, you add the tls=true option. For example, to connect to the admin database on cluster0 and cluster1:

mongosync \
--cluster0 "mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020/admin?tls=true" \
--cluster1 "mongodb://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net/admin?tls=true"

You can also use mongodb+srv connection strings with mongosync. You do not need to add the tls=true option to a mongodb+srv connection string. For example:

mongosync \
--cluster0 "mongodb+srv://clusterAdmin:superSecret@clusterOne01.fancyCorp.com/" \
--cluster1 "mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net/"

有关mongodb+srv连接字符串的更多详细信息,请参阅SRV 连接格式。