In MongoDB, a sharded cluster is a set of MongoDB instances, called shards, that work together to hold a large data set. The data in a sharded cluster is partitioned into smaller, manageable parts called chunks that are distributed across the shards. The shards are responsible for storing and retrieving chunks of data from the data set.
To support sharding, MongoDB uses a configuration server that stores metadata about the sharded cluster, such as information about the shards, chunks, and mappings between chunk ranges and shards. The configuration server acts as a central repository for cluster-wide metadata and is responsible for coordinating the activities of the shards.
In a sharded cluster, each MongoDB instance operates in one of three roles: a shard, a config server, or a mongos server.
The role of a config server in a sharded cluster is to manage and distribute cluster metadata. More specifically, the config server stores metadata about the mapping of chunks to shards, as well as configuration data for the cluster, such as the location of the shards, the collections that are sharded, and the routing rules for queries.
When a client submits a query to a mongos server, the mongos server uses the metadata from the config server to determine the appropriate shard(s) to send the query to. The config server also receives and serves requests from the shards for information about the cluster configuration, such as information about ranges of chunks or the location of specific data records.
In summary, the role of a MongoDB config server in a sharded cluster is to store and manage metadata about the sharded data, providing the necessary information to the mongos server to route data to the correct shards.