I have completed the lab through adding the index. I get a valid return code of 1. But when I run the actual sharding command, it says the index isn’t there.
mongos> db.products.createIndex({“sku”: 1})
{
“raw” : {
“m103-csrs/192.168.103.100:26001,192.168.103.100:26002,192.168.103.100:26003” : {
“createdCollectionAutomatically” : true,
“numIndexesBefore” : 1,
“numIndexesAfter” : 2,
“ok” : 1
}
},
“ok” : 1,
“operationTime” : Timestamp(1544804878, 2),
“$clusterTime” : {
“clusterTime” : Timestamp(1544804878, 2),
“signature” : {
“hash” : BinData(0,“O3T0JtZXwWB3CN6T0FPf8mJSFkw=”),
“keyId” : NumberLong(“6634868936309473306”)
}
}
}
mongos> 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(1544804899, 6),
“$clusterTime” : {
“clusterTime” : Timestamp(1544804899, 6),
“signature” : {
“hash” : BinData(0,“76a1JuXsEm9aJjSPXgRBt2rXAX4=”),
“keyId” : NumberLong(“6634868936309473306”)
}
}
}