Site icon Tutorial

Convert a Standalone to a Replica Set

Convert a Standalone to a Replica Set

This tutorial describes the process for converting a standalone mongod instance into a three-member replica set. Use standalone instances for testing and development, but always use replica sets in production. The procedure is as

mongod –port 27017 –dbpath /srv/mongodb/db0 –replSet rs0

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.

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().

Expand the Replica Set – Add additional replica set members by doing the following:

rs.add(“<hostname><:port>”)

Replace <hostname> and <port> with the resolvable hostname and port of the mongod instance to add to the set.

Sharding Considerations – If the new replica set is part of a sharded cluster, change the shard host information in the config database by doing the following:

db.getSiblingDB(“config”).shards.save( {_id: “<name>”, host: “<replica-set>/<member,><member,><…>” } )

Replace <name> with the name of the shard. Replace <replica-set> with the name of the replica set. Replace <member,><member,><> with the list of the members of the replica set.

Apply for MongoDB Certification Now!!

https://www.vskills.in/certification/databases/mongodb-server-administrator

Back to Tutorial

Exit mobile version