Chapter 3 Sharding Lab Shard a Collection

Lab: Shard a Collection

Import json data

mongoimport --port=26000 --host=localhost --authenticationDatabase=admin -u m103-admin -p m103-pass --db m103 --collection products --file /dataset/products.json

Connect to mongos

mongo --port 26000 --username m103-admin --password m103-pass --authenticationDatabase admin

Create an index on sku:

db.products.createIndex( { “sku”: 1 } )

Shard the products collection on sku:

sh.shardCollection( “m103.products”, { “sku”: 1 } )

Checking the status of the sharded cluster:


Hi @Raghu_Nandan_Lal_Garikipati,
Were you in the correct database when you executed the createIndex command?

If you are not sure, just make sure to switch to the correct database before creating the index, you can do this by executing the following command:

use <–database name–>

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.