Deploying Sharded Cluste

Deploying Sharded Cluster - here is the mongos config file - getting below error.

  configDB: m103-csrs/localhost:27004,localhost:27005,localhost:27006
  keyFile: /var/mongodb/pki/m103-keyfile
  bindIp: localhost,
  port: 27000
  destination: file
  path: /var/mongodb/db/mongos.log
  logAppend: true
  fork: true

user@M103# mongos -f mongos.conf
about to fork child process, waiting until server is ready for connections.
forked process: 813
ERROR: child process failed, exited with error number 48
To see additional information in this output, start without the “–fork” option.

Hi @rajeshwar_dadi,

You need to correct the content in the configuration file here:

the above content will be like this, :point_down: without m103-

  configDB: csrs/localhost:27004,localhost:27005,localhost:27006

After it is added to the configuration file, try to re-start the process.
I’m sure it will help.

In case of any query, feel free to reach out, we will be happy to help.


In addition the requirement is for localhost only:

This probably causes some errors that you can see in the log file as the IP address is probably not valid in the IDE.

1 Like

Thank you @Kushagra_Kesav & @steevej - I was able to correct the config file and able to run .

Now I am trying to add first shard to the cluster , Below is what I did so far . Looks like its wrong.

user@M103#  mongo --port 27000 --username m103-admin --password m103-pass --authenticationDatabase admin
MongoDB shell version v4.0.5
connecting to: mongodb://
Implicit session: session { "id" : UUID("4eaf96fb-4fb8-47df-a0b8-e170cd46dc19") }
MongoDB server version: 4.0.5
Server has startup warnings: 
2021-05-11T13:39:21.986+0000 I CONTROL  [main] ** WARNING: You are running this process as the root user, which is not recommended.
2021-05-11T13:39:21.986+0000 I CONTROL  [main] 
mongos> sh.addShard("m103-repl/localhost:27001")

        "ok" : 0,
        "errmsg" : "Could not find host matching read preference { mode: \"primary\" } for set m103-repl",
        "code" : 133,
        "codeName" : "FailedToSatisfyReadPreference",
        "operationTime" : Timestamp(1620741565, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1620741565, 1),
                "signature" : {
                        "hash" : BinData(0,"YPHtaP4AvEY56wL6WG7OVJYCfG0="),
                        "keyId" : NumberLong("6961026274571583517")

2 total, 1 passed, 0 skipped:
[PASS] “mongos is running”
[FAIL] “shard1 has been added to cluster”

Did you add shard1 to the cluster?

Hi @rajeshwar_dadi,

Seems like the following command is incorrect.

It will be shard1 instead of m103-repl.

Hope it helps…!


@Kushagra_Kesav Perfect - it worked …!

1 Like

Hi @rajeshwar_dadi,

We are glad that it worked. :clap:
Moreover, I hope you were also able to understand the concept.

If not, let me clarify once.
So, here the format of sh.addShard() is as follows:


So, according to the Problem statement:

  • The name of replica-set is shard1 not m103-repl,
  • The hostname is localhost ,
  • And, the port number is 27001, 27002, 27003 .

Now I hope it gives you a clear picture of the above problem statement.


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