"no such cmd: key" while configuring a shardCollection

Hi,

I have a script that configures some shards for collections. Sometimes this command works fine:

{"shardCollection": "mydb.testCollection", "key": {"client": "hashed", "_id": 1 }}

But most of the times i get a no such cmd: key error.

Why is it and how can I avoid this error?

Using: MongoDB 5.0.2

Got it. I cast a json into a bson. json’s object has no order, but bson’s.
So while getting bson(fromjson: json) the order was not guaranteed. Edit the bson directly works.

1 Like

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