Starting in MongoDB 8.0, you can configure a config server to store your application data in addition to the usual sharded cluster metadata. A config server that stores application data is called a config shard or embedded config server.
Converting your replica set into a sharded cluster with an embedded config shard can reduce:
The number of nodes required in your deployment.
Complexity for maintaining one-shard clusters.
About this Task
Starting in MongoDB 8.3, you can convert a replica set directly into a sharded cluster with an embedded config shard.
Previous releases require you to first convert the replica set into a sharded cluster with a dedicated config server replica set, then convert that into one with an embedded config shard.
Access Control
If access control is enabled, the
transitionFromDedicatedConfigServer command
requires the transitionFromDedicatedConfigServer
authorization action for the cluster.
The clusterManager role has the
transitionFromDedicatedConfigServer authorization action and
can be assigned to a user.
Before You Begin
Starting in MongoDB 8.3, replica sets that were previously sharded clusters cannot be converted back into replica sets.
The conversion of a sharded cluster into a replica set preserves sharding metadata from its prior deployment, including a shard identity document, which blocks it from again becoming a sharded cluster. If you attempt a self-managed conversion back into a sharded cluster, MongoDB returns an error.
To convert such replica sets into sharded clusters, contact Technical Support.
Steps
The following example converts a self-managed replica set to a config shard that contains a pre-existing user data from the replica set.
Put the replica set in maintenance mode.
Perform a rolling restart on the replica set. Start each node as a config server in maintenance mode:
Stop each node, beginning with the secondaries. To shut down a server, use the
db.shutdownServer()method.db.shutdownServer() Restart the node as a config shard in maintenance mode.
mongod --config /etc/mongodb.conf --configsvr \ --replicaSetConfigShardMaintenanceMode \ --configsvr- Starts the
mongodinstance as a config server. --replicaSetConfigShardMaintenanceMode- Enables the config shard maintenance mode, which disables some startup checks and allows you to convert a server into an embedded config shard.
Wait for the node to rejoin the replica set before restarting the next.
Find the primary node.
Use the rs.status() method to identify the new
primary node. If you have a large replica set, use the
db.aggregate() method to narrow your search.
db.aggregate( [ { $documents: rs.status().members }, { $match: { stateStr: "PRIMARY" } }, { $project: { _id: 1, name: 1 } ] )
[ { _id: 3, name: "192.0.2.3:27017" } ]
Convert the primary into a config shard.
Connect to the primary node and reconfigure it to operate as an embedded config shard:
Use the
rs.conf()method to get the current configuration and store it in a variable:var conf = rs.conf() Set the
configsvrfield:conf.configsvr = true Increment the
versionfield:conf.version += 1 Reconfigure the node:
rs.reconfig(conf) Wait for secondaries to replicate the change. You can check the status by running an aggregation pipeline on the member documents:
db.aggregate( [ { $documents: rs.status().members }, { $group: { _id: null, allConfigSvr: { $min: { $eq: ["$configsvr", true] } } } } ] ) { _id: null, allConfigSvr: true } When
allConfigSvrshowstrue, it indicates that the reconfiguation has propagated to all nodes in the cluster.
Restart the cluster.
Perform a rolling upgrade to restart the replica set as a config server:
Stop each node, beginning with the secondaries. To shut down a server, use the
db.shutdownServer()method.db.shutdownServer() Restart the node as a config server, no longer in maintenance mode:
mongod --config /etc/mongodb.conf --configsvr
Start the router.
Start the mongos router:
mongos --config /etc/mongodb.conf
Transition the config server to an embedded config shard.
Connect to mongos and run the
transitionFromDedicatedConfigServer command
to add the config shard to the cluster.
db.adminCommand( { transitionFromDedidcatedConfigServer: 1 } )
Point application at router.
Update your application to connect to the mongos
router instead of the replica set members.