SOS: How to perform collection sharding in MongoDB 6.0?

Hi everyone, I’m a newbie and just getting into MongoDB.
Now encountered a strange problem, unable to perform sharding. I use Windows 11, MongoDB6.0.6, and log in through the Windows command line → mongosh. After entering the command at the correct position, it is always prompted:

test> sh.shardCollection("INVENTORY.inventory", { name : "hashed" })
MongoServerError: no such command: 'shardCollection'. Are you connected to mongos?

What should I do?
Thanks!

Where you are running this command?
What is your setup like?data replicas,config servers,mongod etc
Have you completed all pre steps
You have to run it on mongos instance

Hi @Di_Lin,
Here is the answer of your question:

“Are you connected to mongos?”

Best Regards

1 Like