Hashed sharding

A document in the restaurant collection looked like this:

{
“_id” : ObjectId(“5e32cf183745002bd6aab829”),
“name” : “The Chop House - Grand Rapids”,
“cuisine” : “Japanese”,
“stars” : 1.4,
“address” : {
“street” : “1232 Umsi Park”,
“city” : “Gatucse”,
“state” : “OR”,
“zipcode” : “00405”
}
}

I created a hashed index on “address.zipcode”
When I try to shard the collection using the above key (address.zipcode), which has a hashed index on it, but I got an error saying that I need an index on the shard key.
But I already have an index on the key (address.zipcode).
I drop the index and recreate it w/o hashed this time
Then I tried shard the collection again using the same key (address.zipcode), this time it worked.
How come I can’t shard using “address.zipcode” even though I had a hashed index on the key?

Thanks !

Sally

You would typically use a hashed shard key on a monotonically increasing field like “_id” or “timestamp” but I can’t see any reason why it will fail anyway.

Try to drop and recreate the collection, then try again.