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.
Important
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.
mongod
instance.--replSet
option to specify the name of the new replica set. Ensure that the name is distinct (for instance, you could use the shard name
as 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. --dbpath
uses the standalone’s existing database path of /srv/mongodb/db0
and --port
is the same as before:
For more information on configuration options, see Configuration File Options and the mongod
manual page.
mongo
shell to the shard mongod
instance.rs.initiate()
to initiate the new replica set:
The replica set is now operational. To view the replica set configuration, use rs.conf()
. To check the status of the replica set, use rs.status()
.
mongo
shell to one of the sharded cluster’s mongos
instances and retrieve the shard information:
Replace <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 shards
section 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 "shard0000"
and "shard0001"
respectively:
host
information with the replica set information:
Replace <replica-set>
with the name of the replica set. Replace <member>
with the replica set member. For example shardA/mongodb1.example.net:27018
.
mongos
instancesTo add members to this replica set, use the rs.add()
method. For more information on adding members to a replica set, see Add Members to a Replica Set.
To convert a non-shard standalone to a non-shard replica set, see Convert a Standalone to a Replica Set instead.