On this page本页内容
The collections in the config
database support:config
数据库中的集合支持:
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"
afterClusterTime
选项"majority"
within a causally consistent session"majority"
时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
数据库。
You cannot perform read/write operations to the collections in the 不能在多文档事务内对config
database inside a multi-document transaction.config
数据库中的集合执行读/写操作。
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:config
数据库并查看支持分片操作的集合列表,请将mongosh
连接到分片集群中的mongos
实例,并发出以下命令:
use config show collections
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):但是,如果需要验证分片集群的配置服务器的写可用性,可以将文档插入测试集合(在确保该名称的集合不存在之后):
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
创建config
数据库的完整备份。
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.changelog
The config database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The changelog
collection stores a document for each change to the metadata of a sharded collection.changelog
集合为分片集合的元数据的每次更改存储一个文档。
The following example displays a single record of a chunk split from a 以下示例显示了从changelog
collection: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 the changelog
collection contains the following fields:changelog
集合中的每个文档都包含以下字段:
config.changelog._id
The value of changelog._id
is: <hostname>-<timestamp>-<increment>
.changelog._id
的值是:<hostname>-<timestamp>-<increment>
。
config.changelog.clientAddr
A string that holds the address of the client, a 保存客户机地址的字符串,发起此更改的mongos
instance that initiates this change.mongos
实例。
config.changelog.time
A ISODate timestamp that reflects when the change occurred.反映更改发生时间的ISODate时间戳。
config.chunks
The config
database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The chunks
collection stores a document for each chunk in the cluster. chunks
集合为集群中的每个区块存储一个文档。Consider the following example of a document for a chunk named 考虑以下名为mydb.foo-a_\"cat\"
:mydb.foo-a_\"cat\"
的块的文档示例:
{ "_id" : "mydb.foo-a_\"cat\"", "lastmod" : Timestamp(2, 1), "uuid": "c025d039-e626-435e-b2d2-c1d436038041", "min" : { "animal" : "cat" }, "max" : { "animal" : "dog" }, "shard" : "shard0004", "history" : [ { "validAfter" : Timestamp(1569368571, 27), "shard" : "shard0004" } ] }
These documents store the range of values for the shard key that describe the chunk in the 这些文档在min
and max
fields. min
和max
字段中存储描述块的shard键的值范围。Additionally the 此外,shard
field identifies the shard in the cluster that "owns" the chunk.shard
字段标识集群中“拥有”区块的分片。
config.collections
The config database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The collections
collection stores a document for each sharded collection in the cluster. collections
集合为集群中的每个分片集合存储一个文档。Given a collection named 给定pets
in the records
database, a document in the collections
collection 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.databases
The config database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The databases
collection stores a document for each database in the cluster.databases
集合为群集中的每个数据inventory
储一个文档。
For each database, the corresponding document displays the name, the database's primary shard , the database's sharding enabled status, and a version.对于每个数据库,相应的文档显示名称、数据库的主分片、数据库的分片启用状态和版本。
{ "_id" : "test", "primary" : "shardA", "partitioned" : true, "version" : { "uuid" : UUID("516a5f79-5eb9-4844-8ee9-b8e9de91b760"), "timestamp" : Timestamp(1626894204, 1), "lastMod" : 1 } } { "_id" : "hr", "primary" : "shardA", "partitioned" : false, "version" : { "uuid" : UUID("8e39d61d-6259-4c33-a5ed-bcd2ae317b6f"), "timestamp" : Timestamp(1626895015, 1), "lastMod" : 1 } } { "_id" : "reporting", "primary" : "shardB", "partitioned" : false, "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.sh.status()
在Databases
部分返回此信息。
config.lockpings
The config database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The lockpings
collection keeps track of the active components in the sharded cluster. lockpings
集合跟踪分片集群中的活动组件。Given a cluster with a 如果集群中有一个运行在mongos
running on example.com:30000
, the document in the lockpings
collection would resemble:example.com:30000
上的mongos
,那么lockpings
集合中的文档将类似于:
{ "_id" : "example.com:30000:1350047994:16807", "ping" : ISODate("2012-10-12T18:32:54.892Z") }
config.locks
The config database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The locks
collection stores the distributed locks. locks
集合存储分布式锁。The primary of the config server replica set takes a lock by inserting a document into the 配置服务器副本集的主副本集通过向locks
collection.locks
集合中插入文档来获取锁。
{ "_id" : "test.myShardedCollection", "state" : 2, "process" : "ConfigServer", "ts" : ObjectId("5be0b9ede46e4f441a60d891"), "when" : ISODate("2018-11-05T21:52:00.846Z"), "who" : "ConfigServer:Balancer", "why" : "Migrating chunk(s) in collection test.myShardedCollection" }
As of version 3.4, the 从3.4版开始,state
field will always have a value 2
to prevent any legacy mongos
instances from performing the balancing operation. state
字段将始终具有值2
,以防止任何遗留mongos
实例执行平衡操作。The when
field specifies the time when the config server member became the primary.when
字段指定配置服务器成员成为主成员的时间。
In version 3.4, when the balancer is active, the balancer takes a lock, as in the following 3.4 example:在3.4版中,当平衡器处于活动状态时,平衡器会获取一个锁,如下面的3.4示例所示:
{ "_id" : "balancer", "state" : 2, "ts" : ObjectId("5be0bc6cb20effa83b15baa8"), "who" : "ConfigServer:Balancer", "process" : "ConfigServer", "when" : ISODate("2018-11-05T21:56:13.096Z"), "why" : "CSRS Balancer" }
Starting in version 3.6, the balancer no longer takes a "lock". If you have upgraded from 3.4 to 3.6, you may choose to delete any residual 从3.6版开始,平衡器不再采用“锁定”。如果您已从3.4升级到3.6,则可以选择删除任何剩余的"_id" : "balancer"
documents."_id" : "balancer"
文档。
config.migrationCoordinators
New in version 4.4.在版本4.4中新增。
The migrationCoordinators
collection exists on each shard and stores a document for each in-progress chunk migration from this shard to another shard. migrationCoordinators
集合存在于每个分片上,并为从该分片到另一分片的每个正在进行的块迁移存储一个文档。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.mongos
The config
database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The mongos
collection stores a document for each mongos
instance affiliated with the cluster. mongos
集合存储与集群关联的每个mongos
实例的文档。The cluster maintains this collection for reporting purposes.集群出于报告目的维护此集合。
Each document in the mongos
collection contains these fields:mongos
集合中的每个文档都包含以下字段:
_id | String | mongos is running. mongos 运行的主机名和端口。_id is formatted as <hostname>:<port> . _id 的格式为<hostname>:<port> 。 |
---|---|---|
advisoryHostFQDNs | Array of strings | mongos 's fully qualified domain names (FQDNs). mongos 的完全限定域名(FQDN)数组。 |
created | Date |
|
mongoVersion | String | mongos is running.mongos 正在运行的mongos 版本。 |
ping | Date | mongos instances send pings to the config server every 30 seconds. mongos 实例每30秒向配置服务器发送一次ping。 |
up | NumberLong | mongos has been up as of the last ping. mongos 已上升的秒数。 |
waiting | Boolean | true and is only present for backward compatibility. true ,仅用于向后兼容。 |
The following document shows the status of the 以下文档显示了在mongos
running on example.com:27017
.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.rangeDeletions
The rangeDeletions
collection exists on each shard and stores a document for each chunk range that contains orphaned documents. rangeDeletions
集合存在于每个分片上,并为包含孤立文档的每个区块范围存储一个文档。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.settings
The config database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The settings
collection holds the following sharding configuration settings:settings
集合保存以下分片配置设置:
chunksize
value is in megabytes.chunksize
值以MB为单位。Balancer settings. 平衡器设置。To change the balancer settings, including balancer status, see Manage Sharded Cluster Balancer.要更改平衡器设置,包括平衡器状态,请参阅管理分片群集平衡器。
Starting in MongoDB 4.2:从MongoDB 4.2开始:
balancerStart
balancerStop
Autosplit. 自动拆分。To enable or disable the autosplit flag, use the corresponding 要启用或禁用sh.enableAutoSplit()
method or sh.disableAutoSplit()
method.autosplit
标志,请使用相应的sh.enableAutoSplit()
方法或sh.disableAutoSplit()
方法。
Starting in MongoDB 4.2:从MongoDB 4.2开始:
balancerStart
balancerStop
The following are some example documents in the 以下是settings
collection:settings
集合中的一些示例文档:
{ "_id" : "chunksize", "value" : 64 } { "_id" : "balancer", "mode" : "full", "stopped" : false } { "_id" : "autosplit", "enabled" : true }
config.shards
The config database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The shards
collection represents each shard in the cluster in a separate document, as in the following:shards
集合在单独的文档中表示集群中的每个分片,如下所示:
{ "_id" : "shard0000", "host" : "localhost:30000", "state" : 1 }
If the shard is a replica set, the 如果分片是副本集,则host
field 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:host
字段显示副本集的名称,然后是斜杠,最后是以逗号分隔的副本集每个成员的主机名列表,如下例所示:
{ "_id" : "shard0001", "host" : "shard0001/localhost:27018,localhost:27019,localhost:27020", "state" : 1 }
If the shard has zones assigned, this document has a 如果分片分配了区域,则此文档有一个tags
field, that holds an array of the zones to which it is assigned, as in the following example:tags
字段,其中包含分配给它的区域的数组,如下例所示:
{ "_id" : "shard0002", "host" : "localhost:30002", "state" : 1, "tags": [ "NYC" ] }
config.tags
The config database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The tags
collection holds documents for each zone range in the cluster. tags
集合保存集群中每个区域范围的文档。The documents in the tags
collection resemble the following:tags
集合中的文档类似于以下内容:
{ "_id" : { "ns" : "records.users", "min" : { "zipcode" : "10001" } }, "ns" : "records.users", "min" : { "zipcode" : "10001" }, "max" : { "zipcode" : "10281" }, "tag" : "NYC" }
config.version
The config database is internal: applications and administrators should not modify or depend upon its content in the course of normal operation.config
数据库是内部的:在正常操作过程中,应用程序和管理员不应修改或依赖其内容。
The version
collection holds the current metadata version number. version
集合保存当前元数据版本号。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. version
集合,必须使用dbgetCollection()
方法。For example, to retrieve the collection's document:例如,要检索集合的文档:
db.getCollection("version").find()
Starting in MongoDB 3.6, the 从MongoDB 3.6开始,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.config
数据库包含内部集合,以支持标准、副本集和分片群集的因果一致会话,以及副本集和分区群集的可重试写入和事务。
Do not manually modify or drop these collections.不要手动修改或删除这些集合。
To access these collections for a 要访问mongod
or mongos
instance, connect mongosh
to the instance.mongod
或mongos
实例的这些集合,请将mongosh
连接到该实例。
config.system.sessions
The system.sessions
collection stores session records that are available to all members of the deployment.system.sessions
集合存储可供部署的所有成员使用的会话记录。
When a user creates a session on a 当用户在mongod
or mongos
instance, the record of the session initially exists only in-memory on the instance. mongod
或mongos
实例上创建会话时,会话记录最初只存在于实例的内存中。Periodically, the instance will sync its cached sessions to the 实例将定期将其缓存会话同步到system.sessions
collection; at which time, they are visible to all members of the deployment.system.sessions
集合;此时,部署的所有成员都可以看到它们。
To view records in the 要查看system.sessions
collection, use $listSessions
.system.sessions
集合中的记录,请使用$listSessions
。
Do not manually modify or drop the 请勿手动修改或删除system.sessions
collection.system.sessions
集合。
In a sharded cluster, the 在分片集群中,system.sessions
collection is sharded.system.sessions
集合被分片。
system.sessions
collection, MongoDB drops the new shard's system.sessions
collection during the add process.system.sessions
集合,MongoDB会在添加过程中删除新分片的系统会话集。system.sessions
collection into at least 1024 chunks and distributes the chunks uniformly across shards in the cluster.system.sessions
集合拆分为至少1024个块,并在集群中的分片之间均匀分布这些块。config.transactions
The 事务集合存储用于支持副本集和分片集群的可重试写入和事务的记录。transactions
collection stores records used to support retryable writes and transactions for replica sets and sharded clusters.
Do not manually modify or drop the 请勿手动修改或删除transactions
collection.transactions
记录集合。