The collections in the config database support:config数据库中的集合支持:
Sharded cluster operations分片化集群操作Causally consistent sessions for standalones, replica sets, and sharded clusters and retryable writes for replica sets and sharded clusters.独立、副本集和分片集群的因果一致会话,以及副本集和分区集群的可重试写入。
Note
Sharded clusters may show different collections in the 分片集群可能会在config database, depending on whether you connect to mongos or mongod:config数据库中显示不同的集合,具体取决于您是连接到mongos还是mongod:
On在mongos, theconfigdatabase shows collections located on the config servers, such ascollectionsorchunks.mongos上,config数据库显示位于配置服务器上的集合,如collections或chunks。On在mongod, theconfigdatabase shows collections specific to the given shard, such asmigrationCoordinatorsorrangeDeletions.mongod上,config数据库显示特定于给定分片的集合,如migrationCoordinators或rangeDeletions。
When a config server and a shard are hosted on the same node, 当配置服务器和分片托管在同一节点上时,mongos may have access to some shard-local collections in the config database.mongos可能可以访问config数据库中的一些分片本地集合。
Restrictions限制
Starting in MongoDB 5.0, non-transaction reads are not allowed on the 从MongoDB 5.0开始,不允许对config.transactions collection with the following read concerns and options:config.transactions集合进行非事务读取,具有以下读取关注和选项:
"snapshot"已设置了"majority"and the afterClusterTime option is set"majority"和afterClusterTime选项。When using a MongoDB Driver and在因果一致的会话中使用MongoDB驱动程序和"majority"within a causally consistent session"majority"时
Important
The schema of the config database is internal and may change between releases of MongoDB. config数据库的模式是内部的,可能会在MongoDB的不同版本之间发生变化。The config database is not a dependable API, and users should not write data to the config database in the course of normal operation or maintenance.config数据库不是一个可靠的API,用户在正常运行或维护过程中不应将数据写入config数据库。
Note
You cannot perform read/write operations to the collections in the 您不能在多文档事务中对config database inside a multi-document transaction.config数据库中的集合执行读/写操作。
Collections to Support Sharded Cluster Operations支持分片集群操作的集合
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:mongosh连接到分片集群中的mongos实例,然后发出以下命令:
use config
show collections
Note
If running with access control, ensure you have privileges that grant 如果使用访问控制运行,请确保您具有在数据库上授予listCollections action on the database.listCollections操作的权限。
The config database is mainly for internal use, and during normal operations you should never manually insert or store data in it. However, if you need to verify the write availability of the config server for a sharded cluster, you can insert a document into a test collection (after making sure that no collection of that name already exists):配置数据库主要供内部使用,在正常操作期间,您不应手动在其中插入或存储数据。但是,如果您需要验证分片集群的配置服务器的写可用性,您可以将文档插入测试集合中(在确保该名称的集合不存在之后):
Warning
Modification of the 修改功能系统上的config database on a functioning system may lead to instability or inconsistent data sets. config数据库可能会导致数据集不稳定或不一致。If you must modify the 如果必须修改config database, use mongodump to create a full backup of the config database.config数据库,请使用mongodump创建配置数据库的完整备份。
db.testConfigServerWriteAvail.insertOne( { a : 1 } )
If the operation succeeds, the config server is available to process writes.如果操作成功,则配置服务器可用于处理写入。
Future releases of the server may include different collections in the config database, so be careful when selecting a name for your test collection.服务器的未来版本可能会在配置数据库中包含不同的集合,因此在为测试集合选择名称时要小心。
MongoDB uses the following collections in the MongoDB在config database to support sharding:config数据库中使用以下集合来支持分片:
config.changelogTip
Internal MongoDB Metadata内部MongoDB元数据The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.config数据库是内部的。在正常运行期间,应用程序和管理员不应修改或依赖其内容。Thechangelogcollection stores a document for each change to the metadata of a sharded collection.changelog集合为分片集合的元数据的每次更改存储一个文档。Example示例The following example displays a single record of a chunk split from a以下示例显示了从changelogcollection:changelog集合中分割的块的单个记录:{
"_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 thechangelogcollection contains the following fields:changelog集合中的每个文档都包含以下字段:config.changelog._idThe value ofchangelog._idis:<hostname>-<timestamp>-<increment>.changelog._id的值是:<hostname>-<timestamp>-<increment>。
config.changelog.serverThe hostname of the server that holds this data.保存此数据的服务器的主机名。
config.changelog.clientAddrA string that holds the address of the client, a一个包含客户端地址的字符串,一个启动此更改的mongosinstance that initiates this change.mongos实例。
config.changelog.timeA ISODate timestamp that reflects when the change occurred.反映更改发生时间的ISODate时间戳。
config.changelog.whatThe type of change recorded. Possible values include:记录的更改类型。可能的值包括:dropCollectiondropCollection.startdropDatabasedropDatabase.startmoveChunk.startmoveChunk.commitsplitmulti-split
config.changelog.nsNamespace where the change occurred.发生更改的命名空间。
config.changelog.detailsA document that contains additional details for the change. The structure of the包含更改的其他详细信息的文档。detailsdocument depends on the type of change.details文档的结构取决于更改的类型。
config.chunksTip
Internal MongoDB Metadata内部MongoDB元数据The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.config数据库是内部的。在正常运行期间,应用程序和管理员不应修改或依赖其内容。Theconfig.chunkscollection stores a document for each chunk in the cluster. The following example shows a document:config.chunks集合为集群中的每个块存储一个文档。以下示例显示了一个文档:{
_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'
}
]
}In the document:在文件中:_idis the chunk identifier.是块标识符。minandmaxare the range of values for the chunk's shard key.min和max是块的分片键的值范围。shardis the name of the shard that stores the chunk in the cluster.是集群中存储块的分片的名称。
Tip
To find the chunks in a collection, retrieve the collection's要查找集合中的块,请从uuididentifier from theconfig.collectionscollection.config.collections集合中检索该集合的uuid标识符。Then, use然后,使用uuidto retrieve the matching document with the sameuuidfrom theconfig.chunkscollection.uuid从config.chunks集合中检索具有相同uuid的匹配文档。
config.collectionsTip
Internal MongoDB Metadata内部MongoDB元数据Starting in MongoDB 8.0,从MongoDB 8.0开始,config.collectionsstores metadata for all sharded collections and unsharded collections moved withmoveCollection.config.collections存储所有分片集合和使用moveCollection移动的未分片集合的元数据。In MongoDB versions earlier than 8.0,在早于8.0的MongoDB版本中,config.collectionsonly stores metadata for sharded collections.config.collections仅存储分片集合的元数据。config.collectionsonly stores metadata about collections, not the documents stored in the collections.仅存储关于集合的元数据,而不存储集合中存储的文档。For a collection named对于petsin therecordsdatabase, a document in thecollectionscollection would resemble the following:records数据库中名为pets的集合,collections集合中的文档类似于以下内容:{
"_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.csrs.indexesNew in version 7.0.在版本7.0中新增。Tip
Internal MongoDB Metadata内部MongoDB元数据The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.config数据库是内部的。在正常运行期间,应用程序和管理员不应修改或依赖其内容。Theindexescollection stores a document for each global index available on a shard.indexes集合为分片上可用的每个全局索引存储一个文档。Each document in the collection contains the following fields:集合中的每个文档都包含以下字段:Field字段Data Type Description描述nameString字符串Name of the global index.全局索引的名称。keyPatternDocument文档Index key specification.索引键规格。optionsDocument文档Provides information on specified index options, including whether the index is a global index.提供有关指定索引选项的信息,包括索引是否为全局索引。lastmodTimestamp Timestamp that provides information on when the index was last modified and the index version.时间戳,提供有关索引上次修改时间和索引版本的信息。collectionUUIDUUID UUID of the sharded collection.分片集合的UUID。indexCollectionUUIDUUID UUID of the secondary collection that tracks the global index.跟踪全局索引的辅助集合的UUID。
config.databasesTip
Internal MongoDB Metadata内部MongoDB元数据Thedatabasescollection stores a document for each database in the cluster.databases集合为集群中的每个数据库存储一个文档。For each database, the corresponding document displays the name, the database's primary shard , and a version.对于每个数据库,相应的文档显示名称、数据库的主分片和版本。{ "_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 } }The method
sh.status()returns this information in the Databases section.
config.migrationCoordinatorsThe
migrationCoordinatorscollection 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.When a migration is complete, the document describing the migration is deleted from the collection.
config.mongosTip
Internal MongoDB Metadata
The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.
The
mongoscollection stores a document for eachmongosinstance affiliated with the cluster. The cluster maintains this collection for reporting purposes.Each document in the
mongoscollection contains these fields:Field字段Data Type Description描述_idString字符串The hostname and port where the mongosis running. The_idis formatted as<hostname>:<port>.advisoryHostFQDNsArray of strings Array of the mongos's fully qualified domain names (FQDNs).createdDate When the
mongoswas started.New in version 5.2.在版本5.2中新增。mongoVersionString字符串Version of MongoDB that the mongosis running.pingDate mongosinstances send pings to the config server every 30 seconds. This field indicates the last ping time.upNumberLong Number of seconds the mongoshas been up as of the last ping.waitingBoolean布尔值This field is always trueand is only included for backward compatibility.The following document shows the status of the
mongosrunning onexample.com:27017.[
{
_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.rangeDeletionsThe
rangeDeletionscollection 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.When the orphaned chunk range is cleaned up, the document describing the range is deleted from the collection.
config.settingsTip
Internal MongoDB Metadata
The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.
The
settingscollection holds the following sharding configuration settings:- Range size. To change range size, see Modify Range Size in a Sharded Cluster. The specified
chunksizevalue is in megabytes. - Balancer settings. To change the balancer settings, including balancer status, see Manage Sharded Cluster Balancer.
Autosplit:
Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation.
In MongoDB versions earlier than 6.1:
balancerStartalso enables auto-splitting for the sharded cluster.balancerStopalso disables auto-splitting for the sharded cluster.- To enable or disable the autosplit flag, use the corresponding
sh.enableAutoSplit()method orsh.disableAutoSplit()method.
Example documents in the
settingscollection:{ "_id" : "chunksize", "value" : 64 }
{ "_id" : "balancer", "mode" : "full", "stopped" : false }- Range size. To change range size, see Modify Range Size in a Sharded Cluster. The specified
config.shardsTip
Internal MongoDB Metadata
The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.
The
shardscollection represents each shard in the cluster in a separate document, as in the following:{ "_id" : "shard0000", "host" : "localhost:30000", "state" : 1 }If the shard is a replica set, the
hostfield displays the name of the replica set, then a slash, then a comma-separated list of the hostnames of each member of the replica set, as in the following example:{ "_id" : "shard0001", "host" : "shard0001/localhost:27018,localhost:27019,localhost:27020", "state" : 1 }If the shard has zones assigned, this document has a
tagsfield, that holds an array of the zones to which it is assigned, as in the following example:{ "_id" : "shard0002", "host" : "localhost:30002", "state" : 1, "tags": [ "NYC" ] }
config.tagsTip
Internal MongoDB Metadata
The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.
The
tagscollection holds documents for each zone range in the cluster. The documents in thetagscollection resemble the following:{
"_id" : { "ns" : "records.users", "min" : { "zipcode" : "10001" } },
"ns" : "records.users",
"min" : { "zipcode" : "10001" },
"max" : { "zipcode" : "10281" },
"tag" : "NYC"
}
config.versionTip
Internal MongoDB Metadata内部MongoDB元数据The config database is internal. Applications and administrators should not modify or depend on its content during normal operation.config数据库是内部的。在正常运行期间,应用程序和管理员不应修改或依赖其内容。The
versioncollection 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
versioncollection, you must use thedb.getCollection()method. For example, to retrieve the collection's document:db.getCollection("version").find()
Collections to Support Sessions
The config database contains the internal collections to support causally consistent sessions for standalones, replica sets, and sharded clusters and retryable writes and transactions for replica sets and sharded clusters.
Warning
Do not manually modify or drop these collections.请勿手动修改或删除这些集合。
To access these collections for a mongod or mongos instance, connect mongosh to the instance.
config.system.sessionsThe
system.sessionscollection stores session records that are available to all members of the deployment.When a user creates a session on a
mongodormongosinstance, the record of the session initially exists only in-memory on the instance. Periodically, the instance will sync its cached sessions to thesystem.sessionscollection; at which time, they are visible to all members of the deployment.To view records in the
system.sessionscollection, use$listSessions.Warning
Do not manually modify or drop the
system.sessionscollection.In a sharded cluster, the在分片集群中,system.sessionscollection is sharded.system.sessions集合是分片的。When adding a shard to the sharded cluster, if the shard to add already contains its own当向分片集群添加分片时,如果要添加的分片已经包含自己的system.sessionscollection, MongoDB drops the new shard'ssystem.sessionscollection during the add process.system.sessions集合,MongoDB会在添加过程中删除新分片的system.sessions集合。
config.transactionsThe
transactionscollection stores records used to support retryable writes and transactions for replica sets and sharded clusters.Warning警告Do not manually modify or drop the不要手动修改或删除transactionscollection.transactions集合。