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

自己管理型レプリカセットの構成

rs.conf()メソッドまたはreplSetGetConfigコマンドを使用して、レプリカセットの構成にアクセスできます。

レプリカセットの構成を変更するには、rs.reconfig() メソッドを使用して、構成ドキュメントをメソッドに渡します。

警告

MongoDB のバージョンによって検証ルールが異なる可能性があるため、異なるバージョンの MongoDB のノードを含むレプリカセットの再設定は避けてください。

次のドキュメントは、レプリカセット構成ドキュメントの表現を示しています。お使いのレプリカセットの構成には、以下の設定の一部しか含まれていない場合があります。

{
_id: <string>,
version: <int>,
term: <int>,
protocolVersion: <number>,
writeConcernMajorityJournalDefault: <boolean>,
configsvr: <boolean>,
members: [
{
_id: <int>,
host: <string>,
arbiterOnly: <boolean>,
buildIndexes: <boolean>,
hidden: <boolean>,
priority: <number>,
tags: <document>,
secondaryDelaySecs: <int>,
votes: <number>
},
...
],
settings: {
chainingAllowed : <boolean>,
heartbeatIntervalMillis : <int>,
heartbeatTimeoutSecs: <int>,
electionTimeoutMillis : <int>,
catchUpTimeoutMillis : <int>,
getLastErrorModes : <document>,
getLastErrorDefaults : <document>,
replicaSetId: <ObjectId>
}
}
_id

: string

レプリカセットの名前です。

_id は、replication.replSetName またはコマンドラインで mongod に指定された --replSet の値と同一である必要があります

Tip

レプリカセット名の設定については、replSetName または --replSet を参照してください。

version

タイプ: int

レプリカセット構成ドキュメントの改訂版を前の構成と区別するため、数字を 1 つずつ増やします。

Replica set members use term and version to achieve consensus on the "newest" replica configuration. When members compare replica configuration documents, the configuration document with a larger term is considered the "newest". If term is the same or absent, the configuration document with the larger version is considered "newest".

term

タイプ: int

機能の互換性バージョン(FCV)「4.4」以降でのみ使用可能です。

An incrementing number used to distinguish revisions of the replica set configuration document from previous iterations of the configuration. The term of a configuration document matches the term of the replica set primary which performed the reconfiguration. The primary increments its term each time it steps up after winning an election. The primary ignores the term field if set explicitly in the replSetReconfig operation.

Issuing a force reconfiguration removes the term field. When the primary next issues replSetReconfig without force, it sets the term to its own term.

Replica set members use term and version to achieve consensus on the "newest" replica configuration. When members compare replica configuration documents, the configuration document with a larger term is considered the "newest". If term is the same or absent, the configuration document with the larger version is considered "newest".

configsvr

タイプ: ブール値

デフォルト: false

レプリカセットがシャーディングされたクラスターのコンフィギュレーションサーバーに使用されるかどうかを示します。レプリカセットがシャーディングされたクラスターのコンフィギュレーションサーバー用である場合は、true に設定します。

protocolVersion

タイプ: 数値

デフォルト: 1

MongoDB は protocolVersion: 1 のみをサポートし、protocolVersion: 0 はサポートしなくなりました。

writeConcernMajorityJournalDefault

タイプ: ブール値

デフォルト: true

書込み保証 (write concern) でジャーナル オプション j が明示的に指定されていない場合の、{ w: "majority" } 書込み保証 (write concern) の動作を決定します。

次の表に、writeConcernMajorityJournalDefault の値と、それに対応する { w: "majority" } の動作を示します。

{ w: "majority" } 動作

true

MongoDB は、投票権を持つノードの過半数がディスク上のジャーナルに書込んだ後、書込み (write) 操作に確認応答を返します。

重要: writeConcernMajorityJournalDefaulttrue の場合、投票権を持つレプリカセットの全ノードはジャーナリングを実行する必要があります。

If any voting member of a replica set uses the in-memory storage engine, you must set writeConcernMajorityJournalDefault to false.

If any voting member of a replica set uses the in-memory storage engine and writeConcernMajorityJournalDefault is true, "majority" write operations may fail. These include operations that inherently use "majority" write concern, such as the replSetStepDown command, or various mongosh methods that by default use "majority" write concern, such as user management methods and role management methods.

バージョン4.2 以降(および4.0.13 および3.6.14 )、レプリカセットのメンバーが、 インメモリストレージエンジンを使用しているものの(投票または非投票)、レプリカセットの がwriteConcernMajorityJournalDefault true に設定されている場合、レプリカセットノードはスタートアップ警告をログに記録します。

false

MongoDB は、投票権を持つノードの過半数がメモリ内で操作を適用した後で、書込み (write) 操作に確認応答を返します。

警告:

If any voting member of a replica set uses the in-memory storage engine, you must set writeConcernMajorityJournalDefault to false.

Starting in version 4.2 (and 4.0.13 and 3.6.14 ), if a replica set member uses the in-memory storage engine (voting or non-voting) but the replica set has writeConcernMajorityJournalDefault set to true, the replica set member logs a startup warning.

You cannot run transactions on a sharded cluster that has a shard with writeConcernMajorityJournalDefault set to false (such as a shard with a voting member that uses the in-memory storage engine).

members

タイプ: 配列

An array of member configuration documents, one for each member of the replica set. The members array is a zero-indexed array.

各ノード固有の構成ドキュメントには、次のフィールドを含めることができます。

members[n]._id

タイプ: 整数

レプリカセット内のノードの整数識別子です。すべてのノード間で一意です。

MongoDB 5.0 以降では、値は 0 以上の任意の整数値にできます。以前は、この値は 0 から 255 までの整数に制限されていました。

Each replica set member must have a unique _id. Avoid re-using _id values even if no members[n] entry is using that _id in the current configuration.

Once set, you cannot change the _id of a member.

注意

When updating the replica configuration object, access the replica set members in the members array with the array index. The array index begins with 0. Do not confuse this index value with the value of the members[n]._id field in each document in the members array.

members[n].host

: string

セットのノードのホスト名と、指定されている場合はポート番号。

ホスト名は、レプリカセット内のすべてのホストで解決可能である必要があります。

警告

members[n].host cannot hold a value that resolves to localhost or the local interface unless all members of the set are on hosts that resolve to localhost.

members[n].arbiterOnly

任意

タイプ: ブール値

デフォルト: false

アービタを指定するブール値です。値 true は、ノードがアービタであることを示します。

When using the rs.addArb() method to add an arbiter, the method automatically sets members[n].arbiterOnly to true for the added member.

members[n].buildIndexes

任意

タイプ: ブール値

デフォルト: true

A boolean that indicates whether the mongod builds indexes on this member. You can only set this value when adding a member to a replica set. You cannot change members[n].buildIndexes field after the member has been added to the set. To add a member, see rs.add() and rs.reconfig().

クライアントからクエリを受信する mongod インスタンスの場合は false に設定しないでください。

次の条件がすべて当てはまる場合は、buildIndexesfalse に設定すると便利な場合があります。

  • you are only using this instance to perform backups using mongodump, and

  • このノードはクエリを受け取らない。

  • インデックスの作成とメンテナンスが、ホスト システムに過度の負担をかける。

false に設定しても、レプリケーションに必要な操作を容易にするために、セカンダリは _id フィールドにインデックスを構築します

警告

If you set members[n].buildIndexes to false, you must also set members[n].priority to 0. If members[n].priority is not 0, MongoDB will return an error when attempting to add a member with members[n].buildIndexes equal to false.

ノードがクエリを受け取らないようにするには、インデックスを構築しないインスタンスをすべて隠ぺいする必要があります。

Other secondaries cannot replicate from a member where members[n].buildIndexes is false.

members[n].hidden

任意

タイプ: ブール値

デフォルト: false

この値が true の場合、レプリカセットはこのインスタンスを隠ぺいし、db.hello() または hello の出力にノードを含めません。こうすることで、セカンダリの読み込み設定 (read preference) によって読み取り操作(つまり、クエリ)がこのホストするに到達することを防止できます。

Hidden members can acknowledge write operations issued with Write Concern. For write operations issued with "majority" write concern, the member must also be a voting member (that is, votes is greater than 0).

members[n].priority

任意

: プライマリ/セカンダリ ノードの場合は 0 から 1000 までの数値、アービタの場合は 0 または 1 の数値。

デフォルト: プライマリ/セカンダリのノードの場合は 1.0、アービタの場合は 0。

レプリカセットがプライマリになる相対的な可能性を示す数値。

  • ノードがプライマリになる可能性を高めるには、そのノードの priority 値を高く指定します。

  • ノードがプライマリになる可能性を減らすには、そのノードの priority 値を低く指定します。

ノードの優先順位を変更すると、1 つ以上の選挙がトリガーされます。選挙アルゴリズムは、最も優先順位が高いノードをプライマリに選出するために最善を尽くします。しかし、優先順位の高いセカンダリが使用できる場合でも、優先順位の低いノードがプライマリになる場合があります。

優先順位の低いノードがプライマリになると、サーバーは最も優先順位の高いレプリカセットがプライマリになるまで、定期的に選挙を呼び出します。選挙が行われる頻度は、選出されたノードと最も優先順位の高いノードとの間の優先順位の違いによって決まります。

優先順位が 0 のノードがプライマリになることはできません。

Non-voting members (meaning members that have votes set to 0) must have a priority of 0.

members[n].tags

任意

: ドキュメント

デフォルト: なし

tags ドキュメントには、レプリカセットのユーザー定義タグ フィールドと値のペアが含まれています。

{ "<tag1>": "<string1>", "<tag2>": "<string2>",... }

詳しくは、「レプリカセットのタグセットの構成」を参照してください。

members[n].secondaryDelaySecs

任意

タイプ: 整数

デフォルト: 0

このレプリカセットがプライマリから "遅れる" 秒数。

遅延ノードを作成するにはこのオプションを使用します。遅延ノードは、過去のある時点におけるデータの状態を反映したデータのコピーを保持します。

Delayed members can contribute to acknowledging write operations issued with Write Concern. However, they return write acknowledgment no earlier than the configured delay value. For write operations issued with "majority" write concern, the member must also be a voting member (that is, votes is greater than 0).

members[n].votes

任意

タイプ: 整数

デフォルト: 1

レプリカセット選挙においてサーバーが投じる投票数です。各ノードが持つ投票数は 1 または 0 で、アービタ は常にちょうど 1 票を持ちます。

が より大きいメンバーは、priority 00votesを持つことはできません。

レプリカセットには最大50 7メンバーを含めることができますが、投票メンバーは メンバーのみです。7 1 つのレプリカセットに を超えるノードが必要な場合は、追加の投票権のないノードのためにmembers[n].votes から0 を設定します。

投票権のない(すなわちvotes0 の)メンバーは、priority の0 を持っている必要があります。

MongoDB 5.0 以降では、新しく追加されたセカンダリは投票権のあるノードとしてカウントされず、SECONDARY 状態に達するまで選出されません。

投票権のないノードは、"majority" 書込み保証 (write concern) 付きで発行された書込み (write) 操作に確認応答できません。

settings

任意

: ドキュメント

レプリカセット全体に適用される構成オプションを含むドキュメントです。

The settings document contains the following fields:

settings.chainingAllowed

任意

タイプ: ブール値

デフォルト: true

MongoDB5.0.1 以前で、 が次の場合。settings.chainingAllowed

  • true: レプリカセットのセカンダリ ノードは、他のセカンダリ ノードからデータを複製できます。

  • false: セカンダリ ノードはプライマリからのみデータを複製できます。

MongoDB 5.0.2 以降

settings.getLastErrorDefaults

任意

: ドキュメント

MongoDB 5.0 以降では使用できません。

重要

MongoDB5.0 以降では、デフォルトの 以外の でデフォルトの書込み保証 (write concern)を指定することはできません。代わりに、settings.getLastErrorDefaults { w: 1, wtimeout: 0 }setDefaultRWConcernコマンドを使用して、レプリカセットまたはシャーディングされたクラスターのデフォルトの読み取りまたは書込み保証 (write concern)を設定します。

settings.getLastErrorModes

任意

: ドキュメント

A document used to define a custom write concern through the use of members[n].tags. The custom write concern can provide data-center awareness.

{ getLastErrorModes: {
<name of write concern> : { <tag1>: <number>, .... },
...
} }

The <number> refers to the number of different tag values required to satisfy the write concern. For example, the following settings.getLastErrorModes defines a write concern named datacenter that requires the write to propagate to two members whose dc tag values differ.

{ getLastErrorModes: { datacenter: { "dc": 2 } } }

カスタム書込み保証 (write concern) を使用するには、書込み保証名を書込み保証 (write concern) 内のwオプションに渡します。例:

{ w: "datacenter" }

詳細と例については、「レプリカセットのタグセットの構成」を参照してください。

settings.heartbeatTimeoutSecs

任意

タイプ: int

デフォルト: 10

レプリカセットがお互いのハートビートが成功するまで待つ秒数です。あるノードが時間内に応答しない場合、他のノードは期限を過ぎたそのノードをアクセス不可としてマークします。

settings.electionTimeoutMillis

任意

タイプ: int

デフォルト: 10000(10 秒)

The time limit in milliseconds for detecting when a replica set's primary is unreachable. This setting controls failover sensitivity when using protocolVersion: 1. You can expect the failover timeout to not exceed the value of electionTimeoutMillis.

値を選択する際には、次の点を考慮してください。

  • 値が大きいほどフェイルオーバーは遅くなりますが、プライマリ ノードやネットワークの速度低下やむらの影響を受けにくくなります。

  • 値が小さいほどフェイルオーバーは速くなりますが、プライマリ ノードやネットワークの速度低下やむらの影響を受けやすくなります。

The setting only applies when using protocolVersion: 1.

注意

force フィールドを true に設定せずに rs.stepDown() または replSetStepDown を使用してプライマリを降格すると、降格したプライマリは、選挙を直ちに呼び出す資格のあるセカンダリを指名します。

settings.catchUpTimeoutMillis

任意

タイプ: int

デフォルト: -1、キャッチアップ時間は無限。

新たに選出されたプライマリが、より新しい書込み (write) を行った可能性のある他のレプリカセットと同期(キャッチアップ)するまでの時間制限(ミリ秒単位)です。時間制限が無限の場合や長い場合には、選挙後に他のノードがロールバックする必要のあるデータ量は減りますが、フェイルオーバー時間は長くなる可能性があります。

新たに選出されたプライマリは、セットの他のノードに完全に追いつくと、キャッチアップ期間を早く終了します。キャッチアップ期間中は、新しく選出されたプライマリはクライアントからの書込み (write) に対応できません。キャッチアップを中止してプライマリへの移行を完了するには、replSetAbortPrimaryCatchUp を使用します。

The setting only applies when using protocolVersion: 1.

settings.catchUpTakeoverDelayMillis

任意

タイプ: int

デフォルト: 30000(30 秒)

ノードが現在のプライマリよりも進んでいると判断した後、キャッチアップ引き継ぎの開始を待つ時間(ミリ秒単位)です。キャッチアップ引き継ぎ中、現在のプライマリの進んだノードがレプリカセットの新しいプライマリになるための選挙を開始します。

引き継ぎを開始したノードが現在のプライマリよりも先行していると判断した後、指定されたミリ秒数待機してから、次のことを確認します。

  1. まだ現在のプライマリよりも進んでいること

  2. 利用可能な全ノードの中で最新のノードであること

  3. 現在のプライマリが現在、そのノードをキャッチアップしていること

これらの条件をすべて満たしていると判断すると、引き継ぎを開始したノードは直ちに選挙に立候補します。

レプリカセット選挙の詳細については、「レプリカセット選挙」を参照してください。

注意

Setting catchUpTakeoverDelayMillis to -1 disables catchup takeover. Setting catchUpTimeoutMillis to 0 disables primary catchup and consequently also catchup takeover.

settings.heartbeatIntervalMillis

内部でのみ使用します

ハートビートの頻度(ミリ秒単位)。

settings.replicaSetId

: ObjectId

The ObjectId associated with the replica set and automatically created during rs.initiate() or replSetInitiate. You cannot change the replicaSetId.