Error when sharding products collection- code 72 - Solved

Hi All,

i already created an index on my products collection and however i get the following error msg when runnning this command

db.adminCommand( { shardCollection: “m103.products”, key: {“sku”: 1 } } )

“ok” : 0,
“errmsg” : “Please create an index that starts with the proposed shard key before sharding the collection”,
“code” : 72,
“codeName” : “InvalidOptions”,
“operationTime” : Timestamp(1578967433, 5),
“$clusterTime” : {
“clusterTime” : Timestamp(1578967433, 5),
“signature” : {
“hash” : BinData(0,“0Mwh7gKvg7IGiprR6IGjevLYKtY=”),
“keyId” : NumberLong(“6780307923500269595”)

i’ve tried using different keys ( droped and re-uploaded the json file few times in order to)
but nothing seems to work

What’s the output of:

use m103

Fyi, a more succinct command for sharding a collection is sh.shardCollection()


i saw something very weird going on - i had the two shards, dropped one and then add it back, imported the document and followed the instructions and it worked finally.

Quite weird.

But Thanks so much :smiley:

Good to hear!

By the way, there’s a Solved button at the bottom of each post. You can use that instead.

Hi @Carlos_56318,

use m103

Did you run this command before creating index ? If not, then maybe you created the index on wrong database.

Shubham Ranjan
Curriculum Services Engineer

Hi Shubham,

yes i did created the indexes and then i ran the command.
i actually dropped the database several times and it didnt work. Apparently this issue was only on my side because i havent seen any post related, anyhow, i managed to solve the issue, thanks for the support. :smiley: