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

Config Database

config データベースのコレクションは以下をサポートします。

注意

シャーディングされたクラスターは、mongos に接続するか mongod に接続するかに応じて、config データベースに異なるコレクションを表示する場合があります。

コンフィギュレーションサーバーとシャードが同じノードでホストされている場合、mongos は、config データベース内の一部のシャード ローカル コレクションにアクセスできる可能性があります。

Starting in MongoDB 5.0, non-transaction reads are not allowed on the config.transactions collection with the following read concerns and options:

重要

config データベースのスキーマは内部的なものであり、MongoDB のリリース間で変更される可能性があります。config データベースは信頼できる API ではないため、ユーザーは通常の操作またはメンテナンス中に config データベースにデータを書き込まないでください。

注意

マルチドキュメントトランザクション内では、config データベース内のコレクションに対して読み取り/書き込み操作を実行することはできません。

MongoDB 8.0 以降では、一部の config コレクションを読み取るには mongos に接続する必要があります。これらのコレクションの一覧については、単一シャード コレクションの読み取りを参照してください。

To access the config database and view the list of collections that support sharding operations, connect mongosh to a mongos instance in a sharded cluster and issue the following:

use config
show collections

注意

アクセス権制御を使用して実行中の場合は、データベースに対して listCollections アクションを許可する特権があることを確認してください。

コンフィギュレーションデータベースは主に内部使用を目的として、通常の操作中はデータを手動で挿入したり保存したりしないでください。ただし、シャーディングされたクラスターのコンフィギュレーションサーバーの書き込み可否を確認する必要がある場合は、テストコレクションにドキュメントを挿入できます(その名前のコレクションがまだ存在しないことを確認した後に)。

警告

Modification of the config database on a functioning system may lead to instability or inconsistent data sets. If you must modify the config database, use mongodump to create a full backup of the config database.

db.testConfigServerWriteAvail.insertOne( { a : 1 } )

操作が成功すると、コンフィギュレーションサーバーは書き込みを処理できるようになります。

サーバーの今後のリリースでは、コンフィギュレーションデータベースにさまざまなコレクションが含まれる可能性があるため、テストコレクションの名前を選択するときは注意してください。

MongoDB は、シャーディングをサポートするために config データベース内の次のコレクションを使用します。

config.changelog

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

The changelog collection stores a document for each change to the metadata of a sharded collection.

例

The following example displays a single record of a chunk split from a changelog collection:

{
"_id" : "<hostname>-<timestamp>-<increment>",
"server" : "<hostname><:port>",
"clientAddr" : "127.0.0.1:63381",
"time" : ISODate("2012-12-11T14:09:21.039Z"),
"what" : "split",
"ns" : "<database>.<collection>",
"details" : {
"before" : {
"min" : {
"<database>" : { $minKey : 1 }
},
"max" : {
"<database>" : { $maxKey : 1 }
},
"lastmod" : Timestamp(1000, 0),
"lastmodEpoch" : ObjectId("000000000000000000000000")
},
"left" : {
"min" : {
"<database>" : { $minKey : 1 }
},
"max" : {
"<database>" : "<value>"
},
"lastmod" : Timestamp(1000, 1),
"lastmodEpoch" : ObjectId(<...>)
},
"right" : {
"min" : {
"<database>" : "<value>"
},
"max" : {
"<database>" : { $maxKey : 1 }
},
"lastmod" : Timestamp(1000, 2),
"lastmodEpoch" : ObjectId("<...>")
},
"owningShard" : "<value>"
}
}

Each document in the changelog collection contains the following fields:

config.changelog._id

changelog._id の値は <hostname>-<timestamp>-<increment> です。

config.changelog.server

このデータを保持するサーバーのホスト名。

config.changelog.clientAddr

この変更を開始する mongos インスタンスである、クライアントのアドレスを保持する文字列。

config.changelog.time

変更が発生した日時を反映する ISODate タイムスタンプ。

config.changelog.what

記録された変更のタイプ。可能な値は次のとおりです。

  • dropCollection

  • dropCollection.start

  • dropDatabase

  • dropDatabase.start

  • moveChunk.start

  • moveChunk.commit

  • split

  • multi-split

config.changelog.ns

変更が発生した名前空間。

config.changelog.details

A document that contains additional details for the change. The structure of the details document depends on the type of change.

config.chunks

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

The config.chunks collection stores a document for each chunk in the cluster. The following example shows a document:

{
_id: ObjectId('65a954c0de11596e08e7c1dc'),
uuid: UUID('a4479215-a38d-478f-a82b-e5e95d455e55'),
min: { a: Long('121204345') },
max: { a: Long('993849349') },
shard: 'shard01',
lastmod: Timestamp({ t: 1, i: 0 }),
history: [
{
validAfter: Timestamp({ t: 1705596095, i: 14 }),
shard: 'shard01'
}
]
}

ドキュメント内:

  • _id は、チャンク識別子です。

  • min と max はチャンクのシャードキーの値の範囲です。

  • shard は、クラスターにチャンクを保存するシャードの名前です。

Tip

To find the chunks in a collection, retrieve the collection's uuid identifier from the config.collections collection. Then, use uuid to retrieve the matching document with the same uuid from the config.chunks collection.

config.collections

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

MongoDB 8.0 以降、config.collections は、moveCollection によって移動されたすべてのシャーディングされたコレクションとシャーディングされていないコレクションのメタデータを保存します。

8.0 より前のバージョンの MongoDB では、config.collections はシャーディングされたコレクションのメタデータのみを保存します。

config.collections は、コレクションに関するメタデータのみを保存し、コレクションに保存されているドキュメントは保存しません。

For a collection named pets in the records database, a document in the collections collection would resemble the following:

{
"_id" : "records.pets",
"lastmod" : ISODate("2021-07-21T15:48:15.193Z"),
"timestamp": Timestamp(1626882495, 1),
"key" : {
"a" : 1
},
"unique" : false,
"lastmodEpoch" : ObjectId("5078407bd58b175c5c225fdc"),
"uuid" : UUID("f8669e52-5c1b-4ea2-bbdc-a00189b341da")
}
config.databases

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

The databases collection stores a document for each database in the cluster.

各データベースに対応するドキュメントには、名前、データベースのプライマリシャード、およびバージョンが表示されます。

{ "_id" : "test", "primary" : "shardA", "version" : { "uuid" : UUID("516a5f79-5eb9-4844-8ee9-b8e9de91b760"), "timestamp" : Timestamp(1626894204, 1), "lastMod" : 1 } }
{ "_id" : "hr", "primary" : "shardA", "version" : { "uuid" : UUID("8e39d61d-6259-4c33-a5ed-bcd2ae317b6f"), "timestamp" : Timestamp(1626895015, 1), "lastMod" : 1 } }
{ "_id" : "reporting", "primary" : "shardB", "version" : { "uuid" : UUID("07c63242-51b3-460c-865f-a67b3372d792"), "timestamp" : Timestamp(1626895826, 1), "lastMod" : 1 } }

sh.status() メソッドは、データベース セクションでこの情報を返します。

config.migrationCoordinators

The migrationCoordinators collection exists on each shard and stores a document for each in-progress chunk migration from this shard to another shard. The chunk migration fails if the document cannot be written to a majority of the members of the shard's replica set.

移行が完了すると、移行を説明するドキュメントがコレクションから削除されます。

config.mongos

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

The mongos collection stores a document for each mongos instance affiliated with the cluster. The cluster maintains this collection for reporting purposes.

Each document in the mongos collection contains these fields:

フィールド
データ型
説明

_id

文字列

mongosが実行されているホスト名とポート。_idは<hostname>:<port>としてフォーマットされます。

advisoryHostFQDNs

文字列の配列

mongosの完全修飾ドメイン名(FQDN) の配列。

created

日付

mongosが開始されたとき。

バージョン5.2の新機能。

mongoVersion

文字列

mongosが実行している MongoDB のバージョン。

ping

日付

mongosインスタンスが 30 秒ごとに構成サーバーに ping を送信します。このフィールドは、最後の ping 時間を示します。

up

NumberLong

最後の ping の時点で mongos が起動していた秒数。

waiting

ブール値

このフィールドは常に true であり、下位互換性のためだけに含まれています。

次のドキュメントは、example.com:27017 で実行されている mongos のステータスを示しています。

[
{
_id: 'example.com:27017',
advisoryHostFQDNs: [ "example.com" ],
created: ISODate("2021-11-22T16:32:13.708Z"),
mongoVersion: "5.2.0",
ping: ISODate("2021-12-15T22:09:23.161Z"),
up: Long("2007429"),
waiting: true
}
]
config.placementHistory

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

The placementHistory collection exists on the config server and records which shards contained data for a database or collection at specific cluster timestamps. MongoDB uses this information to reconstruct historical data placement.

For a collection named myCollection in the test database, a document in the placementHistory collection would resemble the following:

{
_id: ObjectId("61e0a1f4e5b8c9d0a1b2c3d4"),
nss: "test.myCollection",
collUuid: UUID("07c63242-51b3-460c-865f-a67b3372d792"),
timestamp: Timestamp(1626895826, 1),
shards: [ "shardA", "shardB" ]
}

nss フィールドには、名前空間またはデータベース名いずれかを含めることができます。collUuid フィールドは、コレクションにのみ存在します。

config.rangeDeletions

The rangeDeletions collection exists on each shard and stores a document for each chunk range that contains orphaned documents. The chunk migration fails if the document cannot be written to a majority of the members of the shard's replica set.

孤立したチャンク範囲が完了されると、その範囲を説明するドキュメントがコレクションから削除されます。

config.settings

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

settings コレクションには、次のシャーディング構成設定が保持されます。

  • 範囲サイズ。範囲サイズを変更するには、「シャーディングされたクラスターの範囲サイズの変更」を参照してください。指定された chunksize 値はメガバイト単位です。

  • バランサー設定。バランサーのステータスを含むバランサー設定を変更するには、「シャーディングされたクラスター バランサーの管理」を参照してください。

  • Autosplit:

    MongoDB 6.0.3以降、 自動チャンク分割は実行されません。 これはバランシング ポリシーの改善によるものです。 自動分割コマンドは引き続き存在しますが、操作は実行されません。

    MongoDB 6.1 より前のバージョンの場合:

    • balancerStart は、シャーディングされたクラスターの自動分割も有効にします。

    • balancerStop は、シャーディングされたクラスターの自動分割も無効にします。

    • 自動分割フラグを有効または無効にするには、対応する sh.enableAutoSplit() メソッドまたは sh.disableAutoSplit() メソッドを使用します。

settings コレクション内のドキュメントの例:

{ "_id" : "chunksize", "value" : 64 }
{ "_id" : "balancer", "mode" : "full", "stopped" : false }
config.shards

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

The shards collection represents each shard in the cluster in a separate document, as in the following:

{ "_id" : "shard0000", "host" : "localhost:30000", "state" : 1 }

シャードがレプリカセットの場合、次の例のように host フィールドにはレプリカセットの名前、次にスラッシュ、次にレプリカセットの各ノードのホスト名のカンマ区切りリストが表示されます。

{ "_id" : "shard0001", "host" : "shard0001/localhost:27018,localhost:27019,localhost:27020", "state" : 1 }

シャードにゾーンが割り当てられている場合、このドキュメントには tags フィールドがあり、次の例のように、割り当てられているゾーンの配列が保持されます。

{ "_id" : "shard0002", "host" : "localhost:30002", "state" : 1, "tags": [ "NYC" ] }
config.tags

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

The tags collection holds documents for each zone range in the cluster. The documents in the tags collection resemble the following:

{
"_id" : { "ns" : "records.users", "min" : { "zipcode" : "10001" } },
"ns" : "records.users",
"min" : { "zipcode" : "10001" },
"max" : { "zipcode" : "10281" },
"tag" : "NYC"
}
config.version

Tip

内部 MongoDB メタデータ

The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.

The version collection holds the current metadata version number. This collection contains only one document. For example:

{ "_id" : 1, "minCompatibleVersion" : 5, "currentVersion" : 6, "clusterId" : ObjectId("5d8bc01a690d8abbd2014ddd") }

To access the version collection, you must use the db.getCollection() method. For example, to retrieve the collection's document:

db.getCollection("version").find()

config データベースには、スタンドアロン、レプリカセット、シャーディングされたクラスターの不特定のコンシステント セッションと、レプリカセットとシャーディングされたクラスターの再試行可能な書き込みとトランザクションをサポートするための内部コレクションが含まれています。

警告

これらのコレクションを手動で変更したり削除したりしないでください。

To access these collections for a mongod or mongos instance, connect mongosh to the instance.

config.system.sessions

system.sessions コレクションには、配置のすべてのノードが利用できるセッションレコードが保存されます。

ユーザーが mongod または mongos インスタンスでセッションを作成すると、セッションのレコードは最初はインスタンスのメモリ内にのみ存在します。インスタンスはキャッシュされたセッションを system.sessions コレクションに定期的に同期します。同期されると、配置のすべてのノードにそのセッションが表示されます。

system.sessions コレクション内のレコードを表示するには、$listSessions を使用します。

警告

system.sessions コレクションを手動で修正したり削除したりしないでください。

シャーディングされたクラスターでは、system.sessions コレクションがシャーディングされます。

シャードをシャーディングされたクラスターに追加するときに、追加するシャードにすでに独自の system.sessions コレクションが含まれている場合、MongoDB は追加プロセス中に新しいシャードの system.sessions コレクションを削除します。

config.transactions

transactions コレクションには、レプリカセットとシャーディングされたクラスターの再試行可能な書き込みとトランザクションをサポートするために使用されたレコードが保存されます。

警告

transactions コレクションを手動で修正したり削除したりしないでください。