- Sharding >
- Sharding Reference >
- Config Database
Config Database¶
On this page
The config database supports sharded cluster
operation. See the Sharding section of this manual for full
documentation of sharded clusters.
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.
To access the config database, connect to a mongos
instance in a sharded cluster, and use the following helper:
You can return a list of the collections, with the following helper:
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 a config server, 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.
Collections¶
-
config¶
-
config.changelog¶ -
The
changelogcollection 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
changelogcollection:Each document in the
changelogcollection contains the following fields:-
config.changelog._id¶ The value of
changelog._idis:<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
mongosinstance that initiates this change.
-
config.changelog.what¶ Reflects the type of change recorded. Possible values are:
dropCollectiondropCollection.startdropDatabasedropDatabase.startmoveChunk.startmoveChunk.commitsplitmulti-split
-
config.changelog.ns¶ Namespace where the change occurred.
-
-
config.chunks¶ -
The
chunkscollection stores a document for each chunk in the cluster. Consider the following example of a document for a chunk namedrecords.pets-animal_\"cat\":These documents store the range of values for the shard key that describe the chunk in the
minandmaxfields. Additionally theshardfield identifies the shard in the cluster that “owns” the chunk.
-
config.collections¶ -
The
collectionscollection stores a document for each sharded collection in the cluster. Given a collection namedpetsin therecordsdatabase, a document in thecollectionscollection would resemble the following:
-
config.databases¶ -
The
databasescollection stores a document for each database in the cluster. For each database, the corresponding document displays the name, the database’s primary shard, and the database’s sharding enabled status.
-
config.lockpings¶ -
The
lockpingscollection keeps track of the active components in the sharded cluster. Given a cluster with amongosrunning onexample.com:30000, the document in thelockpingscollection would resemble:
-
config.locks¶ -
The
lockscollection stores the distributed locks. The primary of the config server replica set takes a lock by inserting a document resembling the following into thelockscollection.Changed in version 3.4: As of version 3.4, the
statefield will always have a value2to prevent any legacymongosinstances from performing the balancing operation. Thewhenfield specifies the time when the config server member became the primary.
-
config.mongos¶ -
The
mongoscollection stores a document for eachmongosinstance affiliated with the cluster.mongosinstances send pings to all members of the cluster every 30 seconds so the cluster can verify that themongosis active. Thepingfield shows the time of the last ping, while theupfield reports the uptime of themongosas of the last ping. The cluster maintains this collection for reporting purposes.The following document shows the status of the
mongosrunning onexample.com:27017.
-
config.settings¶ -
The
settingscollection holds the following sharding configuration settings:- Chunk size. To change chunk size,
see Modify Chunk Size in a Sharded Cluster.
The specified
chunksizevalue is in megabytes. - Balancer status. To change status, see Disable the Balancer.
- Autosplit. To enable or disable the autosplit flag, use the
corresponding
sh.enableAutoSplit()method orsh.disableAutoSplit()method.
The following is an example
settingscollection: - Chunk size. To change chunk size,
see Modify Chunk Size in a Sharded Cluster.
The specified
-
config.shards¶ -
The
shardscollection represents each shard in the cluster in a separate document, as in the following: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: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:
-
The
tagscollection holds documents for each zone range in the cluster. The documents in thetagscollection resemble the following:
-
config.version¶ -
The
versioncollection holds the current metadata version number. This collection contains only one document. For example:To access the
versioncollection you must use thedb.getCollection()method. For example, to return the collection’s document: