- 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:
use config
You can return a list of the collections, with the following helper:
show collections
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.
db.testConfigServerWriteAvail.insert( { 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.
Collections¶
-
config
¶
-
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:{ "_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("<...>") } } }
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 are:
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 namedrecords.pets-animal_\"cat\"
:{ "_id" : "mydb.foo-a_\"cat\"", "lastmod" : Timestamp(1000, 3), "lastmodEpoch" : ObjectId("5078407bd58b175c5c225fdc"), "ns" : "mydb.foo", "min" : { "animal" : "cat" }, "max" : { "animal" : "dog" }, "shard" : "shard0004" }
These documents store the range of values for the shard key that describe the chunk in the
min
andmax
fields. Additionally theshard
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 namedpets
in therecords
database, a document in thecollections
collection would resemble the following:{ "_id" : "records.pets", "lastmod" : ISODate("1970-01-16T15:00:58.107Z"), "dropped" : false, "key" : { "a" : 1 }, "unique" : false, "lastmodEpoch" : ObjectId("5078407bd58b175c5c225fdc") }
-
config.
databases
¶ The
databases
collection stores a document for each database in the cluster, and tracks if the database has sharding enabled.databases
represents each database in a distinct document. When a databases have sharding enabled, theprimary
field holds the name of the primary shard.{ "_id" : "admin", "partitioned" : false, "primary" : "config" } { "_id" : "mydb", "partitioned" : true, "primary" : "shard0000" }
-
config.
lockpings
¶ The
lockpings
collection keeps track of the active components in the sharded cluster. Given a cluster with amongos
running onexample.com:30000
, the document in thelockpings
collection would resemble:{ "_id" : "example.com:30000:1350047994:16807", "ping" : ISODate("2012-10-12T18:32:54.892Z") }
-
config.
locks
¶ The
locks
collection stores the distributed locks. The primary of the config server replica set takes a lock by inserting a document resembling the following into thelocks
collection.{ "_id" : "balancer", "state" : 2, "ts" : ObjectId("581178035b3b7dcb772022cd"), "who" : "ConfigServer:Balancer", "process" : "ConfigServer", "when" : ISODate("2016-10-27T03:44:03.007Z"), "why" : "CSRS Balancer" }
Changed in version 3.4: As of version 3.4, the
state
field will always have a value2
to prevent any legacymongos
instances from performing the balancing operation. Thewhen
field specifies the time when the config server member became the primary.
-
config.
mongos
¶ The
mongos
collection stores a document for eachmongos
instance affiliated with the cluster.mongos
instances send pings to all members of the cluster every 30 seconds so the cluster can verify that themongos
is active. Theping
field shows the time of the last ping, while theup
field reports the uptime of themongos
as of the last ping. The cluster maintains this collection for reporting purposes.The following document shows the status of the
mongos
running onexample.com:30000
.{ "_id" : "example.com:30000", "ping" : ISODate("2012-10-12T17:08:13.538Z"), "up" : 13699, "waiting" : true }
-
config.
settings
¶ The
settings
collection holds the following sharding configuration settings:- Chunk size. To change chunk size,
see Modify Chunk Size in a Sharded Cluster.
The specified
chunksize
value 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
settings
collection:{ "_id" : "chunksize", "value" : 64 } { "_id" : "balancer", "stopped" : false } { "_id" : "autosplit", "enabled" : true }
- Chunk size. To change chunk size,
see Modify Chunk Size in a Sharded Cluster.
The specified
-
config.
shards
¶ The
shards
collection represents each shard in the cluster in a separate document, as in the following:{ "_id" : "shard0000", "host" : "localhost:30000" }
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:{ "_id" : "shard0001", "host" : "shard0001/localhost:27018,localhost:27019,localhost:27020" }
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:{ "_id" : "shard0002", "host" : "localhost:30002", "tags": [ "NYC" ] }
The
tags
collection holds documents for each zone range in the cluster. The documents in thetags
collection resemble the following:{ "_id" : { "ns" : "records.users", "min" : { "zipcode" : "10001" } }, "ns" : "records.users", "min" : { "zipcode" : "10001" }, "max" : { "zipcode" : "10281" }, "tag" : "NYC" }
-
config.
version
¶ The
version
collection holds the current metadata version number. This collection contains only one document:To access the
version
collection you must use thedb.getCollection()
method. For example, to display the collection’s document:mongos> db.getCollection("version").find() { "_id" : 1, "version" : 3 }