On this page本页内容
The collections in the config
database support:
Important
The schema of the config
database is internal and may change between releases of 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.
Note
You cannot perform read/write operations to the collections in the config
database inside a multi-document transaction.
To access the config
database and view the list of collections that support sharding operations, connect a mongo
shell to a mongos
instance in a sharded cluster and issue the following:
Note
If running with access control, ensure you have privileges that grant listCollections
action on the database.
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. If you must modify the config
database, use mongodump
to create a full backup of the config
database.
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 config
database to support sharding:
config.
changelog
¶The changelog
collection stores a document for each change to the metadata of a sharded collection.
Example
The following example displays a single record of a chunk split from a changelog
collection:
Each document in the changelog
collection contains the following fields:
config.changelog.
_id
¶The value of changelog._id
is:
<hostname>-<timestamp>-<increment>
.
config.changelog.
server
¶The hostname of the server that holds this data.
config.changelog.
clientAddr
¶A string that holds the address of the client, a mongos
instance that initiates this change.
config.changelog.
what
¶Reflects the type of change recorded. Possible values include:
dropCollection
dropCollection.start
dropDatabase
dropDatabase.start
moveChunk.start
moveChunk.commit
split
multi-split
config.changelog.
ns
¶Namespace where the change occurred.
config.
chunks
¶The chunks
collection stores a document for each chunk in the cluster. Consider the following example of a document for a chunk named mydb.foo-a_\"cat\"
:
These documents store the range of values for the shard key that describe the chunk in the min
and max
fields. Additionally the shard
field identifies the shard in the cluster that “owns”
the chunk.
config.
collections
¶The collections
collection stores a document for each sharded collection in the cluster. Given a collection named pets
in the records
database, a document in the collections
collection would resemble the following:
config.
databases
¶The databases
collection stores a document for each database in the cluster.
For each database, the corresponding document displays the name, the database’s primary shard , the database’s sharding enabled status, and a version.
The method sh.status()
returns this information in the Databases section.
config.
lockpings
¶The lockpings
collection keeps track of the active components in the sharded cluster. Given a cluster with a mongos
running on example.com:30000
, the document in the lockpings
collection would resemble:
config.
locks
¶The locks
collection stores the distributed locks. The primary of the config server replica set takes a lock by inserting a document into the locks
collection.
As of version 3.4, the state
field will always have a value 2
to prevent any legacy mongos
instances from performing the balancing operation. The when
field specifies the time when the config server member became the primary.
In version 3.4, when the balancer is active, the balancer takes a lock, as in the following 3.4 example:
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 "_id" : "balancer"
documents.
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. 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 mongos
collection stores a document for each mongos
instance affiliated with the cluster. mongos
instances send pings to all members of the cluster every 30 seconds so the cluster can verify that the mongos
is active. The ping
field shows the time of the last ping, while the up
field reports the uptime of the mongos
as of the last ping. The cluster maintains this collection for reporting purposes.
The following document shows the status of the mongos
running on example.com:27017
.
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.
When the orphaned chunk range is cleaned up, the document describing the range is deleted from the collection.
config.
settings
¶The settings
collection holds the following sharding configuration settings:
chunksize
value is in megabytes.Starting in MongoDB 4.2:
balancerStart
also enables auto-splitting for the sharded cluster.balancerStop
also disables auto-splitting for the sharded cluster.sh.enableAutoSplit()
method or sh.disableAutoSplit()
method.
Starting in MongoDB 4.2:
balancerStart
also enables auto-splitting for the sharded cluster.balancerStop
also disables auto-splitting for the sharded cluster.The following are some example documents in the settings
collection:
config.
shards
¶The shards
collection represents each shard in the cluster in a separate document, as in the following:
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:
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:
The tags
collection holds documents for each zone range in the cluster. The documents in the tags
collection resemble the following:
config.
version
¶The version
collection holds the current metadata version number. This collection contains only one document. For example:例如:
To access the version
collection, you must use the db.getCollection()
method. For example, to retrieve the collection’s document:
New in version 3.6.版本3.6中的新功能。
Starting in MongoDB 3.6, 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 mongo
shell to the instance.
config.system.
sessions
¶The system.sessions
collection stores session records that are available to all members of the deployment.
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. 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.
To view records in the system.sessions
collection, use $listSessions
.
Warning
Do not manually modify or drop the system.sessions
collection.
In a sharded cluster, the system.sessions
collection is sharded.
system.sessions
collection, MongoDB drops the new shard’s system.sessions
collection during the add process.system.sessions
collection into at least 1024 chunks and distributes the chunks uniformly across shards in the cluster.config.
transactions
¶The transactions
collection stores records used to support retryable writes and transactions for replica sets and sharded clusters.
Warning
Do not manually modify or drop the transactions
collection.