- Replication >
- Replica Set Tutorials >
- Replica Set Deployment Tutorials >
- Convert a Standalone to a Replica Set
Convert a Standalone to a Replica Set¶
On this page
This tutorial describes the process for converting a standalone
mongod
instance into a replica set. Use
standalone instances for testing and development, but always use
replica sets in production. To install a standalone instance, see the
installation tutorials.
To deploy a replica set without using a pre-existing
mongod
instance, see Deploy a Replica Set
instead.
Procedure¶
Shut down the standalone
mongod
instance.Restart the instance. Use the
--replSet
option to specify the name of the new replica set.For example, the following command starts a standalone instance as a member of a new replica set named
rs0
. The command uses the standalone’s existing database path of/srv/mongodb/db0
:If your application connects to more than one replica set, each set should have a distinct name. Some drivers group replica set connections by replica set name.
If converting a shard standalone instance to a shard replica set, the shard replica set name must not use the same name as the config server replica set.
For more information on configuration options, see Configuration File Options and the
mongod
manual page.Use
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, users.status()
.Important
If converting a shard standalone instance to a shard replica set, you must also update the shard information.
To 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.
Sharding Considerations¶
If the new replica set is a shard replica set, change the shard information in the config database by doing the following:
Connect to one of the sharded cluster’s
mongos
instances and retrieve the shard information:Replace
<name>
with the name of the shard.Note
The
<name>
of the shard is separate from the shard replica set name. To retrieve the name of the shard, see theshards
section in the results from thesh.status()
method.Update the
host
information with the replica set information:Replace
<replica-set>
with the name of the replica set. Replace<member,><member,><...>
with the list of the replica set members.Save the information.
Restart all
mongos
instances and all shard binaries.