Lab - Shard a Collection again

Good evening

While trying to solve the lab I get stuck in this error message

“Incorrect number of documents imported - make sure you import the entire dataset”

It shows up when I run the following command

./validate_lab_shard_collection

There are some issues that add more complexity to the matter

  • The handouts for chapter 3 list only one file “m103/products.part2.json” but the mongoimport command requires “products.json”

  • The handouts for chapter 1 list two identical files “m103/products.json”

  • When I run “mongoimport” using only the file “m103/products.part2.json” this error occurs

  • When I run “mongoimport” using only the file “m103/products.json” this error occurs

  • When I run “mongoimport” using “m103/products.json” and then “m103/products.part2.json” this error occurs

  • The amount of documents in the file “m103/products.part2.json” is only 258390 but the lab states that the collection “products” should contain “516784” documents

  • The amount of documents in the file “m103/products.json” is 516784 but the error persists regardless

Honestly I don’t even have enough information to debug it myself. Should I just write anything to just fail and ignore this lab for the time being?

The problem seems to be automatically solved if the correct shard key is selected

But nothing about the error message mentions that

Hi @dptole,

Please re-run your mongoimport command for “products.json” only and NOT “products.part2.json”.
Also, make sure you use pass the --drop option to drop the collection if it already exists as shown below.

mongoimport --drop /dataset/products.json --port 26000 -u “username” -p “password” --authenticationDatabase “authDBname” --db m103 --collection products

Then use the correct shard key and try validating the lab, it should work fine. Please let me know if it doesn’t.

Thanks,
Muskan
Curriculum Support Engineer

1 Like

If you calculate 258390/516784 you get nearly 0.5 . That’s a big hint, that that validation script fails because of sharding. Actually the fraction has jumped right into my eye, but I agree, that there could be a better hint to get the point. I hope my comment sharpened your sense for future analysis. There a re often common patterns, when something goes wrong :slight_smile:

Am retaking this course.While trying to import the documents, getting the below error. Please share any hints to check the issue.
vagrant@m103:~$ mongoimport --drop /dataset/products.json --port 26000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” --db m103 --collection products
2019-07-24T05:46:58.439+0000 connected to: localhost:26000
2019-07-24T05:46:58.440+0000 dropping: m103.products
2019-07-24T05:46:58.559+0000 Failed: Cannot accept sharding commands if sharding state has not been initialized with a shardIdentity document
2019-07-24T05:46:58.559+0000 imported 0 documents

Thanks
Dhamodharan L

Noticed that Balancer is not running, tried to start the balancer, but no luck so far.

MongoDB Enterprise mongos> db.printShardingStatus()
— Sharding Status —
sharding version: {
“_id” : 1,
“minCompatibleVersion” : 5,
“currentVersion” : 6,
“clusterId” : ObjectId(“5d2422c0bfd1b1b38b624b40”)
}
shards:
{ “_id” : “m103-repl”, “host” : “m103-repl/192.168.103.100:27001,m103:27002,m103:27003”, “state” : 1 }
{ “_id” : “m103-repl-2”, “host” : “m103-repl-2/192.168.103.100:27004,m103:27005,m103:27006”, “state” : 1 }
active mongoses:
“3.6.12” : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 1
Last reported error: Could not find host matching read preference { mode: “primary” } for set m103-repl-2
Time of Reported error: Wed Jul 24 2019 05:37:00 GMT+0000 (UTC)
Migration Results for the last 24 hours:
69 : Failed with error ‘aborted’, from m103-repl-2 to m103-repl
databases:
{ “_id” : “applicationData”, “primary” : “m103-repl”, “partitioned” : false }
{ “_id” : “config”, “primary” : “config”, “partitioned” : true }
config.system.sessions
shard key: { “_id” : 1 }
unique: false
balancing: true
chunks:
m103-repl 1
{ “_id” : { “$minKey” : 1 } } -->> { “_id” : { “$maxKey” : 1 } } on : m103-repl Timestamp(1, 0)
{ “_id” : “m103”, “primary” : “m103-repl-2”, “partitioned” : true }
{ “_id” : “newDB”, “primary” : “m103-repl”, “partitioned” : false }
{ “_id” : “test”, “primary” : “m103-repl-2”, “partitioned” : false }
{ “_id” : “testDatabase”, “primary” : “m103-repl”, “partitioned” : false }

MongoDB Enterprise mongos>

Thanks
Dhamodharan L

Hi,

Issue resolved by adding below line in conf file under security of new shard(4,5,6) and restarting it. But i remember having key file should implicitly enable the authorization.

authorization: enabled

Thanks
Dhamodharan L

I saw the difference on the config files… but i just copy and paste from the lab cause i don’t wanna make any mistake, btw it was solved with that configuration key on the config file of the new shard