mongosync ユーティリティは、 MongoDBクラスター間の接続を作成します。 mongosync は次のクラスターのいずれかに接続できます。
MongoDB Atlas のホストされたクラスター
自己管理型クラスターと Atlas ホスト型クラスター
This page provides instructions to connect Atlas clusters using MongoDB Mongosync. For additional details on connecting to an Atlas cluster, see Connect to a Database Deployment
Considerations
ソースと宛先の両方の Atlas クラスターで MongoDB 6.0以降を使用する必要があります。
mongosyncは、レプリカセットとシャーディングされたクラスターをサポートします。mongosyncでは、Atlas 共有クラスターまたはサーバーレスインスタンスはサポートされていません。mongosyncは M 10以上の Atlas クラスターでのみ使用できます。
接続文字列
mongosync は、 MongoDB URI 接続文字列を使用してAtlasクラスターに接続します。
SRV 接続スキームの形式は次のとおりです。
mongodb+srv://[username:password]@[clusterName].[host].mongodb.net/ Atlasで SRV 接続文字列を見つける方法について詳しくは、「クラスターへの接続」を参照してください。
標準の URI 接続スキームの形式は次のとおりです。
mongodb://[username:password]@[clusterName].[host].mongodb.net/
mongosync では、ソースクラスターと宛先クラスターに接続するにはprimary読み込み設定(read preference)が必要です。 詳しくは、「読み込み設定(read preference)オプション 」を参照してください。
認証
Provide valid authentication to connect to a MongoDB Atlas cluster. If you do not already have an Atlas database user, you must create a user.
ロール
mongosync接続文字列で指定されたユーザーには、ソースクラスターと宛先クラスターで必要な権限が必要です。 権限は、書込みブロック設定を変更するか、逆同期を使用するかによって、環境によって異なります。
Atlas の権限は次のとおりです。
同期タイプ | 必要なソース権限 | 必要な宛先権限 |
|---|---|---|
default |
|
|
二重書込みブロック、元対応、または複数元の逆 |
|
|
For details on Atlas roles, see Atlas User Roles.
Atlas user権限を更新するには、「プロジェクトへのアクセス権の管理 」を参照してください。
動作
ホスティング
mongosyncユーティリティは、ソースクラスターまたは宛先クラスターのいずれかに近いハードウェアでホストできます。 クラスター内のmongodまたはmongosインスタンスのいずれかと同じサーバーでホストされている必要はありません。 この柔軟性により、宛先クラスターにデータをプッシュまたはプルして、宛先クラスターで実行されているmongodまたはmongosインスタンスへの影響を最小限に抑えることができます。
初期状態
mongosyncが接続すると、 IDLE状態になります。 同期を開始するには、 startコマンドを発行する必要があります。
制限
M10+ Atlas クラスターでmongosyncを実行する前に、 Require Indexes for All Queriesオプションを無効にします。
例
接続情報の収集
一般的な接続文字列の形式は次のとおりです。
mongodb://<user>:<password>@<clusterName>.<hostname>.mongodb.net/
stringAtlasクラスターの接続 は、Atlas UI から取得できます。詳細については、「データベース配置への接続 」を参照してください。
cluster0とcluster1に対して収集した接続文字列は次のようになります。
cluster0: mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net cluster1: mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net
クラスターを含むプロジェクトには、パスワードsuperSecretを持つデータベース管理ユーザーclusterAdminが存在します。
を使用したソースクラスターと宛先クラスターの接続 mongosync
以下のmongosyncコマンドのレイアウトは表示用に変更されています。 mongosyncを使用してcluster0をcluster1に接続するには、次のコマンドを 1 行で入力します。
mongosync \ --cluster0 "mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net" \ --cluster1 "mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net"
Atlas クラスターには TLS 接続が必要です。 Atlas クラスターでmongosyncを使用するには、 tls=trueオプションを追加します。 たとえば、 cluster0とcluster1上のadminデータベースに接続するには、次の手順に従います。
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"
mongosyncではmongodb+srv接続文字列を使用することもできます。 tls=truemongodb+srv接続 にstring オプションを追加する必要はありません。例:
mongosync \ --cluster0 "mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net/" \ --cluster1 "mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net/"
mongodb+srv接続文字列の詳細については、 SRV 接続形式 を参照してください。