Fails to shard the collection

After creating a proper index, following error is received when sharding the collection:

“errmsg” : “expected primary shard to return a UUID for collection m103.products as part of ‘info’ field but got { name: “products”, type: “collection”, options: {}, info: { readOnly: false }, idIndex: { v: 2, key: { _id: 1 }, name: “id”, ns: “m103.products” } }”,

My solution was to scratch all and start all over:

  • create config servers and sharding
  • create replica set m103-repl
  • create replica set m103-repl-2
  • enable sharding for both replica set

And everything worked fine :slight_smile:

I have a other error:
errmsg” : “Please create an index that starts with the proposed shard key before sharding the collection”, please help!

Did you create the index using
db.products.createIndex({“sku”:1}) ?

I was with the same problem, but I was using the wrong db (I don’t know why), so make sure to:

use m103
show dbs
db.products.createIndex({sku: 1})
sh.shardCollection(“m103.products”, {“sku”: 1 })

Note I used sh.shardCollection instead of db.adminCommand!


Thanks Diego, that was my problem too. You must make sure you are working on the intended database with use m103.

Keep it up.