skip to Main Content

I am trying to shard my collection using mongosh, but its given error "no such command ‘shardCollection’ Are you connected to mongoose ? ".
I am searched that error on google but i didnt find anything about this error.

 sh.shardCollection("my-db.users",{"userId":1})

I am using the above code with mongo shell but it gives an error. I tried on the shell that came with Mongodb Compass, but I get the same error.

2

Answers


  1. https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/ says:

    You can’t deploy a M0 free cluster or M2/M5 shared cluster as a Sharded Cluster.

    Login or Signup to reply.
  2. In order to have a sharded cluster, you need a Config Server Replica Set (CSRS), at least one mongos node, and at least one shard. See https://www.mongodb.com/docs/manual/sharding/

    When running sharding commands like "shardCollection" you will need to connect to a mongos node, not one of the mongod nodes.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search