Chapter 3 - Lab: Shard a Collection returning error

I’m doing my lab “Lab: Shard a Collection” and was able to do all the steps except the one that involves sharding the collection. I was able to enable sharding, to create an index as you can see below

output when I enable sharding:

 {
    "ok" : 1,
    "operationTime" : Timestamp(1621012231, 3),
    "$clusterTime" : {
            "clusterTime" : Timestamp(1621012231, 3),
            "signature" : {
                    "hash" : BinData(0,"7O9jb60UryTj99d7pJyGkyPDfxM="),
                    "keyId" : NumberLong("6962193650977603613")
            }
    }

output when I created an index:

{
        "raw" : {
                "shard1/localhost:27001,localhost:27002,localhost:27003" : {
                        "createdCollectionAutomatically" : false,
                        "numIndexesBefore" : 1,
                        "numIndexesAfter" : 2,
                        "ok" : 1
                }
        },
        "ok" : 1,
        "operationTime" : Timestamp(1621012274, 4),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1621012274, 4),
                "signature" : {
                        "hash" : BinData(0,"3ZWqPtsJ2KUg98ntCJQJZkLsxAk="),
                        "keyId" : NumberLong("6962193650977603613")
                }
        }
}

However, when I shard, it outputs an error as below:

What am I doing wrong and how can I fix the problem?
Thanks

I was able to solve my problem.
My main problem was that I created the following index with a space after the sku:
db.products.createIndex( { "sku ": 1 } )
But I kept sharding using:
sh.shardCollection("m103.products",{sku: 1})

So all I had to do was to remove the space after the sku to get
db.products.createIndex( { "sku": 1 } )

then it worked.

1 Like

Hi @Alpha_Ly,

Yeah, sometimes we miss the trialing space and error get occurred. But, we are glad that you were able to solve the problem and now we are closing this thread here.

In case of any further questions, please feel free to reach out.

:slightly_smiling_face:
Thanks
Kushagra