Search code examples
mongodbsharding

MongoDB : How to perform sharding without replication?


I am trying to accomplish sharding within 2 machines with config server, router, 1 shard in machine A and another shard in machine B. I am finding it hard to do this as I am a beginner and also can't find much documentation/ tutorials online. I have started a two mongod instances one as config server and another as shard, but clueless on how to proceed.

Below is the sharding configuration in two of my mongod (config and shard ) conf files:

Config server:

sharding:
  clusterRole: configsvr

Shard:

sharding:
  clusterRole : shardsvr

As per the documentation , the next step is to execute the command rs.initiate(), but I don't require replication. I still tried to execute just in case and received below error:

{
        "ok" : 0,
        "errmsg" : "This node was not started with the replSet option",
        "code" : 76,
        "codeName" : "NoReplicationEnabled"
}

Is it mandatory to have replication while sharding? How to do sharding without replication within 2 machines?


Solution

  • That's not possible, see sharding Options:

    Note

    Setting sharding.clusterRole requires the mongod instance to be running with replication. To deploy the instance as a replica set member, use the replSetName setting and specify the name of the replica set.

    But you can have a replica set with just one member, that's no problem. The replica set will have only the primary, should work.