The procedure is specific to instances that are not part of a sharded cluster. To convert a shard standalone instance to a shard replica set, see Convert a Shard Standalone to a Shard Replica Set instead.
To install a standalone instance, see the installation tutorials.
To avoid configuration updates due to IP address changes, use DNS hostnames instead of IP addresses. It is particularly important to use a DNS hostname instead of an IP address when configuring replica set members or sharded cluster members.
Use hostnames instead of IP addresses to configure clusters across a split network horizon. Starting in MongoDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start.
Restart the instance. Use the
--replSetoption 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
mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0 --bind_ip localhost,<hostname(s)|ip address(es)>
If your application connects to more than one replica set, each set must have a distinct name. Some drivers group replica set connections by replica set name.
rs.initiate()to initiate the new replica set: