AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

Atlas への自己管理型クラスターの接続

mongosync ユーティリティは、 MongoDBクラスター間の接続を作成します。mongosync は次のいずれかのクラスターに接続できます。

このページでは、 MongoDB Mongosync を使用して、自己管理型クラスターを Atlas クラスターに接続する手順を説明します。

Atlas クラスターへの接続の詳細については、「データベース配置への接続」を参照してください。

注意

最高のパフォーマンスを得るには、移行の前に、 自己管理型クラスター上の を最新の MongoDB Server パッチ リリースにアップグレードしてください。 詳細については、「 MongoDB の最新の自己管理型パッチ リリースへのアップグレード 」を参照してください。

mongosync は、 MongoDB URI接続文字列を使用して、自己管理型クラスターに接続します。

  • SRV 接続スキームの形式は次のとおりです。

    mongodb+srv://[username:password@][host.domain.TLD][/defaultauthdb][?options]
  • 標準の URI 接続スキームの形式は次のとおりです。

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

mongodレプリカセット構成にリストされているのと同じ方法で インスタンスのホスト名を指定します。

シャーディングされたクラスターの場合は、 インスタンスではなく、mongos mongodインスタンスのホスト名を指定します。

注意

mongosync にはreplicaSet オプションは必要ありません。

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を呼び出すときに正しい認証情報を指定する必要があります。

mongosync接続文字列で指定されたユーザーには、ソースクラスターと宛先クラスターで必要な権限が必要です。権限は、環境と逆同期を使用するかどうかによって異なります。

ソースクラスターの自己管理型権限は次のとおりです。

サーバーロールの詳細については、「 自己管理型配置でのロールベースのアクセス制御 」を参照してください。

ユーザー権限を更新するには、grantRolesToUser を参照してください。

宛先クラスターの Atlas 権限は次のとおりです。

同期タイプ
必要な宛先権限

default

二重書込みブロック、元対応、または複数元の逆

Atlas ロールの詳細については、「 Atlas ユーザーロール 」を参照してください。

Atlas ユーザー権限を更新するには、「 プロジェクトへのアクセス権の管理 」を参照してください。

During synchronization, mongosync uses the setUserWriteBlockMode command to block writes on the destination cluster. The database user that mongosync uses to connect to the destination cluster must have both of the following actions at the same time:

If either action is missing, mongosync stops and reports the missing privileges.

atlasAdmin is a built-in role, and these two actions are privilege actions, not roles. To grant them, create a custom role that includes both actions and assign the custom role to the database user.

To create the custom role and assign it to the database user:

1
  1. In , select your organization from the organization menu in the navigation bar.

  2. ナビゲーション バーのProjectsメニューからプロジェクトを選択します。

  3. サイドバーで、 Security見出しの下のDatabase & Network Accessをクリックします。

2
  1. [Custom Roles] タブをクリックします。

  2. Add New Custom Role をクリックします。

  3. For Custom Role Name, enter a name such as mongosyncWriteBlocking.

  4. In the Action or Role dropdown menu, select the setUserWriteBlockMode action. Click Add an action or role and select the bypassWriteBlockingMode action.

  5. [Add Custom Role] をクリックします。

3
  1. [Database Users] タブをクリックします。

  2. Click Edit for the database user that mongosync uses.

  3. Expand the Custom Roles section and select mongosyncWriteBlocking from the Custom Roles dropdown menu.

  4. 変更を保存します。

mongosyncユーティリティは、ソースクラスターまたは宛先クラスターのいずれかに近いハードウェアでホストできます。クラスター内のmongod またはmongos インスタンスのいずれかと同じサーバーでホストされている必要はありません。この柔軟性により、宛先クラスターにデータをプッシュまたはプルして、ここで実行中mongod またはmongos インスタンスへの影響を最小限に抑えることができます。

mongosyncが接続すると、 IDLE状態になります。 同期を開始するには、 startコマンドを発行する必要があります。

mongosyncM10+Atlas クラスターでRequire Indexes for All Queries notablescanの実行を試みる前に、false オプションを無効にして、ソースクラスターと宛先クラスターの両方で を に設定します。

ソースクラスター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が使用されます。

自己管理型クラスターの一般的な接続文字列形式は次のとおりです。

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

クラスターの一般的な接続文字列 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

MongoDB Atlas クラスターの接続文字列は、 Atlas UIから取得できます。詳細については、「 データベース配置への接続 」を参照してください。

以下のmongosyncコマンドのレイアウトは表示用に変更されています。 mongosyncを使用してcluster0をcluster1に接続するには、次のコマンドを 1 行で入力します。

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 クラスターには TLS 接続が必要です。mongosync Atlas クラスターで を使用するには、tls=true オプションを追加します。例admin cluster0を、 と の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"

mongodb+srvmongosyncでは 接続文字列を使用することもできます。tls=true mongodb+srv接続文字列に オプションを追加する必要はありません。 (例: )。

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

mongodb+srv接続文字列の詳細については、 SRV 接続形式 を参照してください。