mongosync ユーティリティは、 MongoDBクラスター間の接続を作成します。mongosync は次のいずれかのクラスターに接続できます。
MongoDB Atlas のホストされたクラスター
自己管理型クラスターと Atlas ホスト型クラスター
このページでは、 MongoDB Mongosync を使用して Atlas クラスターを接続する手順を説明します。Atlas クラスターへの接続の詳細については、データベース配置への接続 を参照してください。
Considerations
ソースと宛先の両方の Atlas クラスターで MongoDB 6.0以降を使用する必要があります。
mongosyncは、レプリカセットとシャーディングされたクラスターをサポートします。mongosyncでは、Atlas 共有クラスターまたはサーバーレスインスタンスはサポートされていません。mongosyncは M 10以上の Atlas クラスターでのみ使用できます。重要
Latest Version With Auto Upgrades は選択しないでください。このオプションは、クラスターを最新のマイナー リリースに自動的にアップグレードします。MongoDBバージョン 8.2 などの一部のマイナー リリースでは、ライブ移行または Mongosync がサポートされていない場合があります。アップグレードするときは、ライブ移行と Mongosync との互換性を確保するために、メジャー バージョンを選択してください。
接続文字列
mongosync は、 MongoDB URI 接続文字列を使用してAtlasクラスターに接続します。
SRV 接続スキームの形式は次のとおりです。
mongodb+srv://[username:password]@[clusterName].[host].mongodb.net/ Atlas でSRV 接続文字列を見つける方法について詳しくは、「クラスターへの接続」を参照してください。
標準の URI 接続スキームの形式は次のとおりです。
mongodb://[username:password]@[clusterName].[host].mongodb.net/
mongosync では、ソースクラスターと宛先クラスターに接続するには、 読み込み設定 (readprimary preference)が必要です。詳しくは、「 読み込み設定(read preference)オプション 」を参照してください。
認証
MongoDB Atlasクラスターに接続するための有効な認証を提供します。 Atlas データベースユーザーがまだいない場合は、ユーザーを作成する必要があります。
ロール
mongosync接続文字列で指定されたユーザーには、ソースクラスターと宛先クラスターで必要な権限が必要です。権限は、環境と逆同期を使用するかどうかによって異なります。
Atlas の権限は次のとおりです。
同期タイプ | 必要なソース権限 | 必要な宛先権限 |
|---|---|---|
default |
|
|
元に戻す、または複数の元に戻す |
|
|
Atlas ロールの詳細については、Atlas ユーザーロール を参照してください。
Atlas ユーザー権限を更新するには、プロジェクトへのアクセス権の管理 を参照してください。
動作
ホスティング
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状態になります。 同期を開始するには、 startコマンドを発行する必要があります。
制限
mongosyncM10+Atlas クラスターでRequire Indexes for All Queries notablescanの実行を試みる前に、false オプションを無効にして、ソースクラスターと宛先クラスターの両方で を に設定します。
例
接続情報の収集
一般的な接続文字列の形式は次のとおりです。
mongodb://<user>:<password>@<clusterName>.<hostname>.mongodb.net/
MongoDB Atlas クラスターの接続文字列は、 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 接続が必要です。mongosync Atlas クラスターで を使用するには、tls=true オプションを追加します。例、admin cluster0と 上の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"
mongodb+srvmongosyncでは 接続文字列を使用することもできます。tls=true オプションをmongodb+srv 接続文字列に追加する必要はありません。 (例: )。
mongosync \ --cluster0 "mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net/" \ --cluster1 "mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net/"
mongodb+srv接続文字列の詳細については、 SRV 接続形式 を参照してください。