Chapter 3: Sharding Lab: Shard a Collection

I am trying to import the data with the following mongoimport
command but getting the syntax error. Could you please advise.

mongos> mongoimport --port 26000 -u m103-admin -p m103-pass --authenticationDatabase admin -d dataset -c dataset.products --file “/dataset/products.json”
2021-01-18T23:09:56.562+0000 E QUERY [js] SyntaxError: missing ; before statement @(shell):1:14

You are at mongos prompt
Please exit and run the mongoimport from your os prompt

Thanks Ram.

The syntax of the mongoimport command is:
mongoimport --port -u -p --authenticationDatabase -d -c --file

And following the following lab instructions I have formed my mongoimport commnd
===== Lab Instructions =====
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)

===== mongoimport commnd =====
mongoimport --port 26000 -u m103-admin -p m103-pass --authenticationDatabase mongos -d m103 -c products --file “/dataset/products.json”
OR
mongoimport --port 26000 -u m103-admin -p m103-pass --authenticationDatabase admin -d m103 -c products --file “/dataset/products.json”

I really didn’t understand the 2nd & 3rd instructions. Could you please explain me and also correct me if my mongoimport command is incorrect.

Regards,
Mahantesh

2nd instruction

use mongos as the target for mongoimport means you will be running import against mongos.You are using --port 26000 that’s where mongos is running

3rd instruction:you will authenticate to mongos with user/password against admin DB

Your first mongoimport command is not correct as authenticationDatabase has to be against a database not mongos or mongod instance

So use your second command to import the data
Make sure you run it at os prompt(not at mongo prompt)

Hi Ramchandra,

Before mongoimport I did check for the file and the files exists
bash-4.4# ls -lh /dataset
total 345
-rw-r–r-- 1 502 dialout 1.7M Mar 11 2020 products.json

So file exists and there is a READ permission.

But when I tried to run the mongoimport, it is giving me the following error

mongoimport --port 26000 -u m103-admin -p m103-pass --authenticationDatabase admin -d m103 -c products --file “/dataset/products.json”
2021-01-20T23:25:07.436+0000 Failed: open “/dataset/products.json”: no such file or directory
2021-01-20T23:25:07.436+0000 0 document(s) imported successfully. 0 document(s) failed to import.

Could you please advise.

Regards,
Mahantesh

Your quotes seems to be the issue
Use straight quotes or don’t use quotes or use = for file or cd to the directory where your file is residing and run the command just passing the file name without any path
You can do it so many ways
Please search our forum.It is documented

Thanks for your response.

I have tried “Reset Workspace” to do the lab all over again.

Except the mongos.conf file I can’t see any files or directories (and cd /datasets says No such file or directory). So where can I find the products.json to import the data?

bash-4.4# ls -lh
total 1
-rw-rw-r-- 1 1000 1000 219 Jan 20 23:24 mongos.conf

bash-4.4# cd /datasets
bash: cd: /datasets: No such file or directory

Could you please help.

Typo in your command
It is /dataset not datasets

1 Like

Hi Ram,
My apologies for the silly mistake.
Thanks for your great help. Your help enabled me to complete the lab successfully.
Thanks once again for you great support.
Regards,
Mahantesh

1 Like

Thanks @Ramachandra_37567 for helping out @Mahantesh_Angadi :clap: