Unable to see collections after successful mongoimport

Hi

Used below queries to insert data into shards,

mongoimport --host “shard2/localhost:27007,localhost:27008,localhost:27009” -u m103-admin -p m103-pass --authenticationDatabase admin --db m103 --collection products --file /dataset/products.json

mongoimport --host “shard1/localhost:27001,localhost:27002,localhost:27003” -u m103-admin -p m103-pass --authenticationDatabase admin --db m103 --collection products --file /dataset/products.json

Result for both these queries is below,

2021-05-30T17:32:21.510+0000 connected to: mongodb://localhost:27007,localhost:27008,localhost:27009/?replicaSet=shard2
2021-05-30T17:32:23.336+0000 9966 document(s) imported successfully. 0 document(s) failed to import.
2021-05-30T17:32:12.356+0000 connected to: mongodb://localhost:27001,localhost:27002,localhost:27003/?replicaSet=shard1
2021-05-30T17:32:14.183+0000 9966 document(s) imported successfully. 0 document(s) failed to import.

but when i try to check data , seeing a null response.

use m103
db.products.findOne()

Can you please help on this.

How did you connect before running:

Best to post a screenshot of the IDE.

I am not sure which lab you are doing but seeing your 2 mongoimport commands I suspect it is related to shard a collection. If that is the case, then I suggest that you revise the previous lessons as you miss an important part of the instructions. You are not supposed to import the collection directly to the shards. You are supposed to import using the mongos URI.

1 Like

Hi Steeve
Thanks for the quick response, below correction resolved problem i faced

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