Start Mongo with port 27011/27012/27013

Please help me understand this concept as this is something that is not clear to me.

I have configured the Config Server Replica Set (CSRS), started them on ports 26001, 26002 and 26003. For this, I have configured the replication set as m103-csrs in the configuration file. Next, I have started the mongos process, and start mongo using the port 26000.

The next step of the process according to the lecture was to start mongo on replication server m103-repl using the ports 27011, 27012 and 27013.
Now, here’s my question: We have not started m103-repl servers, and have not configured the ports in the config files node1.js, node2.js and node3.js. So, do we have to start the mongod process for the m103-repl server? If not, I don’t see how we can shut down these servers.
Did we start the replication servers earlier on these ports and then changed the configuration files to include the shard server?


Hi @sharag,

If I understood your question correctly, you are talking about the Lecture: Setting Up a Sharded Cluster.

In the lecture notes/video for this, we have provided you with the information required to update the config files which will be needed to run this replica set in a sharded cluster.
Moreover, as learnt in the previous lessons, it is mandatory to launch the mongod process before connecting to your mongo shell on that respective port.

Yes, please launch the mongod for all the three config files(port 27011/27012/27013).

If already running please follow below steps to kill the mongods, update your configuration files as per the lecture notes and re-launch the mongod processes.

ps -ef | grep mongod
The output of the above command shows the running mongod processes and the corresponding PIDs.

Kill the mongod processes using kill command followed by the PID, for example:

vagrant@m103:~$ ps -ef | grep mongod

vagrant  24033 18495  0 09:35 pts/3    00:00:11 mongod --port 27000
vagrant  24222  1990  0 10:00 pts/0    00:00:00 grep --color=auto mongod
vagrant@m103:~$ kill 24033

To answer this one, you might have started mongod on these ports earlier while practising previous chapters/labs.

The steps to kill the currently running process have been explained above.

Hope this helps!

Curriculum Support Engineer

Thank you for the detailed explanation.
Yes, I should’ve prefaced it with which lab I was actually working on. I will try this and see how it goes. Thank you!

One other question please.
I tried to remove the old shard because I used the ports 27011 etc. but it gives me an error.

MongoDB Enterprise mongos> db.adminCommand({removeShard: “m103-repl”})
“ok” : 0,
“errmsg” : “Can’t remove last shard”,
“code” : 20,
“codeName” : “IllegalOperation”,
“operationTime” : Timestamp(1569344636, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1569344636, 1),
“signature” : {
“hash” : BinData(0,“7V1nQm/RKzmCmm6E6kBrELcty+Y=”),
“keyId” : NumberLong(“6739286849769963546”)

I encountered the exact same problem with not being able to removed the last shard. I think that it can be done in the config metadata but we were told not to touch this.

Eventually, I went down the long route of re-provisioning the VM and starting from scratch. Definitely not the best approach but it reinforced what I learnt.

I’m interested in hearing what the Curriculum Engineers have to say.

Hi @sharag and @007_jb,

Yes, you will have to clear all the dbpath directories and restart all the mongod processes from scratch since we cannot tamper with config database.

@sharag - If you are performing these for labs, please make sure you use the correct ports (27001/27002/27003 instead of 27011/27012/12703) as the validation script might throw and error due to this.

Curriculum Support Engineer

Yes, I have done that. I need to understand how to modify or start mongos process from scratch.
Since, we do not have any mongos configuration file defined on the config file

You are in the right course for that. Take a look at Chapter 3 - Lecture: Setting Up a Sharded Cluster. A good document to refer to is There is a section devoted to mongos specific paramters.

Hi @sharag,

To start your mongos process from scratch, please follow the below steps as explained in the Lecture: Setting Up a Sharded Cluster as well:

  1. Clean up the dbpath directories - check csrs_1.conf, csrs_2.conf and csrs_3.conf config files for the dbpath that you might have used.
  2. Update your config files by carefully following the instructions mentioned in the lecture notes
  3. Launch the mongod process for these three configs as:
    mongod -f csrs_1.conf
    mongod -f csrs_2.conf
    mongod -f csrs_3.conf
  4. The mongos.conf configuration is mentioned in the lecture notes, create the config file and launch it the same way using mongos -f mongos.conf command.
  5. Then you can connect to one of the config servers as mongo --port 26001

Please follow the lecture notes and let me know if you have any doubts in that one.

Also, I don’t quite understand your question here, can you please elaborate a bit?

Curriculum Support Engineer

Actually, I have finished this.
The way I did it was delete all the DB files for the servers and recreated them and finished the lab.

Thank you for your help, I really appreciate it! :+1:

1 Like