Chapter2: Lab: Deploy a Replica Set

Hi community!
After working on this lab for 1 hour, I have passed 11/12, see details:


It says I haven’t add localhost:27002 to the ‘m103-repl’ replica set. I have no doubtly not add replica yet, snice I returns error message when I use rs.add(“m103-repl:27002”), error message see below:

I am not sure that if I direct a wrong replica file path, but when I reconnect to primary node I use this path:

So the problem is I may use a wrong path to direct node, or secondary nodes should use different path.

But I have no clue for now.

Could someone give me some hint?

Thanks!!!

Hey @Tianyi_Hu,

The above way as you shared is not the correct way to add the replica set for the node localhost:27002. Try this way:

Screenshot 2022-01-10 at 7.02.28 PM

rs.add("localhost:27002")

I hope this helps!

In case you have any doubts, please feel free to reach out to us.

Thanks,
Kushagra Kesav

2 Likes

Thanks! That work well!
But I am kind of confused. After I initiated the rs, I reenter into mongo with --host “m103-repl/localhost:27001” That means I direct the mongo into a path of primary node, right?
Then I am add two nodes (localhost: 27002 and localhost:27003), with rs.add(“localhost:27002”) and rs.add(“localhost:27003”), why I don’t need to type m103-repl since node 2 and node 3 are use same replSetName with node1?
I think that is why I add replica set in incorrect way.

Best,
Tianyi

Hello @Tianyi_Hu,

The syntax of rs.add() to add new node to the replica set is

rs.add(host:port)

So, here localhost is considered to be the host in the case of the our IDE as also mentioned in the configuration file. And 27002 is the port number.

I hope it helps!

Let us know if you have any other questions or concerns.

Thanks,
Kushagra

1 Like

Get it! Thanks!
Say if in the config, I write the path of node 2 for “m103-repl/localhost:27002”, then when I try to add node 2, it still gonna be rs.add(localhost:27002). For the host is localhost but not m103-repl/localhost, correct?

Best,
Tianyi

1 Like

Correct :white_check_mark:

Here m103-repl/localhost:27002

m103-repl → replica set
localhost → host
27002 → port number

Thanks,
Kushagra

1 Like

Get it!

Thanks a lot!!

Best,
Tianyi

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.