I am trying out sharding for the first time, so please bear with me.
I have two replica sets set up. Each replica set has one primary node and two secondary nodes. There names and ports are as follows:
Replica Set 1
Primary: port 27017
Secondary1: port 27020
Secondary2: port 27030
Replica Set 2
Primary: port 27018
Secondary1: port 27028
Secondary2: port 27038
I want to use “Replica Set 1” for sharding, and “Replica Set 2” as the configuration server.
I tried to make “Replica Set 2” the configuration server by typing in the following in the command line, as per MongoDB documentation:
mongod --configsvr --replSet configReplSet
I’m not sure if that worked, but I moved on to the next step, which is to start a mongos instance. To do that, I typed the following in a new command line window:
mongos --configdb configReplSet/localhost:27018,localhost:27028,localhost:27038
After hitting enter, nothing happens. The cursor just keeps blinking next to the “…:27038”. So I’m thinking that didn’t work either. But since I’ve never done this before, maybe that’s what’s supposed to happen.
So I move on. I try to connect mongosh to the mongos:
which works. So I try to add shards there from my other Replica Set:
sh.addShard( “company1repl/localhost:27017,localhost:27020,localhost:27030” )
And I get the following error message:
Warning: MongoshWarning: [SHAPI-10003] You are not connected to a mongos. This command may not work as expected.
So I have a lot of questions here, and would be greatly if anyone can suggest how to solve them. Namely:
- how does one start a mongos instance? There seems to be no documentation on how to do this step by step. Am I to create a directory anywhere on the computer with a mongos.conf file? After that, what exactly needs to be in that file?
- How do I make sure that I’ve designated one of my replica sets as the configuration server?
- How do I properly connect the mongosh to the mongos?
Thanks for anything you could suggest. I should mention that I am trying to do everything via the command line for the sake of my assignment.