- 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
Consider the schema of the config database
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.
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.
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:
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, and tracks if the database has sharding enabled.databasesrepresents each database in a distinct document. When a databases have sharding enabled, theprimaryfield holds the name of the primary shard.
-
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 a distributed lock. This ensures that only onemongosinstance can perform administrative tasks on the cluster at once. Themongosacting as balancer takes a lock by inserting a document resembling the following into thelockscollection.If a
mongosholds the balancer lock, thestatefield has a value of2, which means that balancer is active. Thewhenfield indicates when the balancer began the current operation.Changed in version 2.0: The value of the
statefield was1before MongoDB 2.0.
-
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:30000.
-
config.settings¶ -
The
settingscollection holds the following sharding configuration settings:- Chunk size. To change chunk size, see Modify Chunk Size in a Sharded Cluster.
- Balancer status. To change status, see Disable the Balancer.
The following is an example
settingscollection:
-
config.shards¶ -
The
shardscollection represents each shard in the cluster in a separate document. If the shard is a replica set, thehostfield displays the name of the replica set, then a slash, then the hostname, as in the following example:If the shard has tags assigned, this document has a
tagsfield, that holds an array of the tags, as in the following example:
-
The
tagscollection holds documents for each tagged shard key 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:To access the
versioncollection you must use thedb.getCollection()method. For example, to display the collection’s document:
Note
Like all databases in MongoDB, the config database contains a
system.indexes collection
contains metadata for all indexes in the database for information
on indexes, see Indexes.