Adrian Lopez
Adrian Lopez

Reputation: 2877

Mongodb 3.4 - What's the correct way to add replicas to a replica set?

In the documentation I've found two ways to add replicas to a member:

rs.add()

rs.add('mongodb0.example.net:27017')

sh.addShard()

sh.addShard( "rs1/mongodb0.example.net:27017" )

So, to check if I understand: Are this staments true?

Thank you.

Upvotes: 2

Views: 119

Answers (1)

Ori Dar
Ori Dar

Reputation: 19000

rs.add() is used to add extra replicas of a member to it's replica set. Can be used for config servers and shards.

-

rs.add() is used to add extra replicas of a member to it's replica set

The above statement is correct. But to be more precise, I'll rephrase it as to "add extra members to the current Primary's replica set".

Can be used for config servers

Yes, if you are using Replica Set Config Server - as oppossed three mirrored config servers (SCCC) in MongoDB 3.2, or you are using MongoDB 3.4.

and shards

This is not correct. Shard is a logical member of a cluster, which - by itself - can be a replica set or a standalone (standalones are recommended for test / development purposes only). You can not added shard to a cluster using the rs shell hellper.

sh.addShard() is the specific method to add shards to the cluster. But for convenience can also be used to add replicas to a shard's replicaSet.

-

sh.addShard() is the specific method to add shards to the cluster.

Correct

But for convenience can also be used to add replicas to a shard's replicaSet.

Not true. addShard, as it's name implies is used to add shard to clusters and not members (what you refer as a replicas) to a set. As mentioned, a shard can be a standalone or a replica set. In that latter case the addShard argument must be a the replica set name (rs1) followed by '/'. followed by replica set seed member(s). Putting it all together: "rs1/mongodb0.example.net:27017"

You - at least - have to initialize a replica set before you add it as a shard to a clusters. You can always add (or remove) members from that replica set after it has joined a cluster as a shard.

Upvotes: 1

Related Questions