LAB M103 - Sharding A Collection!

Hello guys,

I am having an issue getting this lab completed.

It says the following tasks need to be done -

Blockquote

Import and shard a collection of data on your cluster:

  1. Use mongoimport to import the data in /dataset/products.json:
  • import this dataset onto m103.products
  • use mongos as the target for mongoimport - you can find the configuration details for this process in mongos.conf
  • authenticate to mongos as m103-admin (with password m103-pass)
  1. Enable sharding on the m103 database.Two shards have already been added to your cluster, shard1 and shard2. For more information, run sh.status() on mongos.
  2. Choose a shard key for the m103.products collection.Review the qualities of a good shard key in the docs and the following information about the products collection:
  • _id is a serial number for each product in this collection, rarely used in queries but important for internal MongoDB usage
  • sku (Stock Keeping Unit) is a randomly generated integer unique to each product - this is commonly used to refer to specific products when updating stock quantities
  • name is the name of the product as it appears in the store and on the website
  • type is the type of product, with the possible values “Bundle”, “Movie”, “Music” and “Software”
  • regularPrice is the regular price of the product, when there is no sale this price changes every season
  • salePrice is the price of a product during a sale - this price changes arbitrarily based on when sales occur
  • shippingWeight is the weight of the product in kilograms, ranging between 0.01 and 1.00 - this value is not known for every product in the collection
  1. Create an index on your shard key and shard the collection.
  2. Once you’ve run the proper commands, click “Run Tests” to run a suite of tests that will check the configuration of your sharded cluster. The results of these tests will let you know which steps you’ve yet to complete.If you chose the wrong shard key, clicking “Run Tests” will give you an error. However, if you already imported the dataset, you must drop the collection:

COPY

use m103 db.products.drop()

Then reimport the dataset, and shard it using a different key.

/> Blockquote

I have completed the first step successfully.

Steps 2-5 are causing em problems.

For the first step, I entered this command:

Blockquote
mongoimport --drop --port 26000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” --db m103 --collection products /dataset/products.json

Blockquote

It seemed to work just fine and it passed the test on the IDE.

For the second step, I am not sure if I should run the command “mongos -f mongos.conf” OR

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

I was able to login with the latter command but not the first one.

Anyways, once I logged in to mongos>, I entered:

Blockquote
use m103
db.products.drop()

Blockquote

Then I try and create two indexes - sku and name - either separately or together - in the following
combinations of any order AFTER I enabled sharding:

Blockquote

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:

sh.status()

sh.enableSharding(“m103”)
db.products.createIndex({"_id":hashed})
sh.shardCollection(“m103.products”,{"_id":hashed})

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

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

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

When I try and run a test, I am able to pass the first one where I import “m103.products” but
I am not able to pass the second one where I have to shard the ‘m103.products’ collection using the correct shard key?

Screen Shot 10-17-22 at 04.49 AM

Please tell me what to do to complete steps 2-5 correctly.

Thanks a lot!

QUIET Services

Reset your workspace and try again
Just use sku field.Create index on this and use this field for shardCollection
You have created multiple shard keys