Sharding a Collection

I use the following:
mongos> mongoimport --port 26000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” --drop --db m103 --collection products --file=/dataset/products.json

I’m getting the following error:

2020-06-19T19:02:40.932+0000 E QUERY [js] SyntaxError: missing ; before statement @(shell):1:14

You have to do that outside mongos.

When I try it from the shell prompt I get this:

2020-06-21T12:20:50.400+0000 Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
2020-06-21T12:20:50.400+0000 imported 0 documents

Are you able to connect to your DB with that user & pwd?
It could be command issue due to its length
Try to split the command line by line using \

Used \ as suggested:

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

got error:

2020-06-21T14:37:15.489+0000 error validating settings: only one positional argument is allowed

found that -u and -p may cause mongoimport to interpret this as positional arguments.

Changed to:

mongoimport --port 26000 --user “m103-admin” --password “m103-pass” --authenticationDatabase “admin” --drop --db m103 --collection products --file = /dataset/products.json


2020-06-21T14:42:51.702+0000 error parsing command line options: unknown option “user”

I asked you to use backslash() but you used forward slash?
Follow below:
mongoimport --port 26000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” \ hit enter after this slash.It will go to next line
–drop --db m103 / --collection products --file=/dataset/products.json

Hi @Steve_33394,

Let us know if you are still facing any issue.

~ Shubham

sh-4.4# mongoimport --port 26000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” \

–drop --db m103 --collection products --file = /dataset/products.json
2020-06-22T14:38:18.301+0000 error validating settings: incompatible options: --file and positional argument(s)
2020-06-22T14:38:18.301+0000 try ‘mongoimport --help’ for more information

Try to remove extra space in --file.Both before and after = sign

1 Like

Getting closer?

sh-4.4# mongoimport --port 26000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” \

–drop --db m103 --collection products --file=/dataset/products.json
2020-06-22T15:16:11.981+0000 Failed: open /dataset/products.json: no such file or directory
2020-06-22T15:16:11.981+0000 imported 0 documents

Please provide a screenshot.

Also provide output of

ls -l /dataset

Give full permissions on that file and see

I would also try to reenter (not cut-n-paste) the name. You might have copied special characters like backspace in a previous cut-n-paste.

Also try with the = sign. All other arguments have no = sign.

sh-4.4# chmod u=rwx,g=rwx,o=rwx /dataset
sh-4.4# mongoimport --port 26000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” \

–drop --db m103 --collection products --file=/dataset/products.json
2020-06-22T17:25:49.826+0000 connected to: localhost:26000
2020-06-22T17:25:49.849+0000 dropping: m103.products
2020-06-22T17:25:51.934+0000 imported 9966 documents

Success!!! Thank you!

Yes…this loaded the db. But the permissions didn’t change. I must have an incorrect permission command: chmod u=rwx,g=rwx,o=rwx /dataset

After running this and checking ls -l /dataset the permissions are the same.

Yes you do. The above command change the permission of the directory. You have to specify the file to effect the file.

Hi @Steve_33394,

You can add -R flag to recursively change the permission of the sub-directory and files in the /dataset directory.

~ Shubham

1 Like

Ok. I got the permissions changed.

I am having authorization problems when enabling sharding. Should I start a new thread?

Yes. Please start a new thread.