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

连接两个 Atlas 集群

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

本页提供使用MongoDB Mongosync 连接Atlas集群的说明。有关连接到Atlas 集群的更多详细信息,请参阅连接到数据库部署

  • 源 Atlas 集群和目标 Atlas 集群都必须使用 MongoDB 6.0或更高版本。

  • mongosync 支持副本集和分片集群。

  • mongosync 支持Atlas共享集群或无服务器实例。 您只能将mongosync与 M 10或更多Atlas集群一起使用。

    重要

    不要选择 Latest Version With Auto Upgrades。此选项会自动将集群升级到最新的次要发布。某些次要版本(例如MongoDB 8.2 版本)可能不支持实时迁移或 Mongosync。升级时,请选择主要版本以确保与实时迁移和 Mongosync 的兼容性。

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

Atlas 权限包括:

同步类型
所需的源权限
所需的目标权限

默认

  • atlasAdmin

冲销或多重冲销

有关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.

通用连接字符串格式为:

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

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

您为cluster0cluster1收集的连接字符串应如下所示:

cluster0:
mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net
cluster1:
mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net

包含集群的项目中有一个数据库管理用户clusterAdmin ,密码为superSecret

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

mongosync \
--cluster0 "mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net" \
--cluster1 "mongodb+srv://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+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net/admin?tls=true" \
--cluster1 "mongodb+srv://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@cluster1Name.abc123.mongodb.net/" \
--cluster1 "mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net/"

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