Convert a Shard Standalone to a Shard Replica Set
Starting in MongoDB 3.6, all shards must be replica sets. Before you can upgrade your 3.4 sharded cluster to version 3.6, you must convert any shards that are running as standalone
mongod instances to replica set shards.
This tutorial describes the process for converting a shard standalone into a shard replica set. The procedure is specific to a shard standalone. To convert just a standalone to a replica set (i.e. not a part of any sharded cluster), see Convert a Standalone to a Replica Set instead.
The following procedure converts a standalone shard to a single-member replica set shard. The procedure assumes that the single member runs on the same host and port as before.
Restart the shard instance with the
--replSetoption to specify the name of the new replica set. Ensure that the name is distinct (for instance, you could use the
shard nameas the replica set name); in particular, shard replica sets must not use the same name as the config server replica set.
The other options can remain the same.
For example, the following command starts a standalone instance as a member of a new replica set named
shardA. The other options stay the same as before; e.g.
--dbpathuses the standalone’s existing database path of
--portis the same as before:
rs.initiate()to initiate the new replica set:
Disconnect from the instance.
<name>with the name of the shard. The
<name>of the shard is separate from the shard replica set name (unless you are using the shard name as the replica set name). To retrieve the name of the shard, see the
shardssection in the results from the
sh.status()method. For example, if the result of
sh.status()includes the following shards section, the name of the two shards are
hostinformation with the replica set information:
<replica-set>with the name of the replica set. Replace
<member>with the replica set member. For example
Save the information.
Repeat for the next standalone shard in the sharded cluster. Ensure that you use a distinct name for each shard replica set.
Once you have finished converting shard standalone instances to shard replica sets, force the members of sharded cluster to update their knowledge of other shards’ connection strings by restarting all members of the sharded cluster:
- config server replica sets
- shard replica sets