Mongoimport not working for me

Hi

I need to do an assignment on MongoDB and I am trying to import a dataset into my cluster. I have tried the following (with my proper username and password)

mongoimport --uri=“mongodb+srv://:@sandbox.hiyt1fi.mongodb.net/Assignment” --collection TdF --type json --file=8300-tour-de-france.json

which gives me a “system can’t find file” error, which is understandable, as no path is specified.

but when I use a path

mongoimport --uri=“mongodb+srv://:@sandbox.hiyt1fi.mongodb.net/Assignment” --collection TdF --type json --file=C:\Users\Declan Fitzpatrick\Desktop\8300-tour-de-france.json

I get “error parsing command line options: error parsing positional arguments: cannot use both --file and a positional argument to set the input file”

or this

mongoimport --uri=“mongodb+srv://:@sandbox.hiyt1fi.mongodb.net/Assignment” --collection TdF --type json --file=\Users\Declan Fitzpatrick\Desktop\8300-tour-de-france.json

which gets the same error

So, what am I doing wrong? I have moved the dataset around to different directories, which didn’t work. is there a default directory from which ‘mongoimport’ reads files, if I only specify the filename without a path?

The space character is a argument separator. The one you have between Declan and Fitzpatrick causes the error because the string start with Fitzpatrick is like an extra argument. Try to put the whole path of --file inside double quotes.

2 Likes

Hi Steve,

Thanks for your suggestion and sorry for the slow reply. I put the path in double quotes and got

Failed: cannot decode array into a primitive.D

I tried single quotes and got

error parsing command line options: error parsing positional arguments: cannot use both --file and a positional argument to set the input file

Double quotes should work
or
cd to the directory where your .json file is residing and try to run the same command without giving full path of the file

This makes me think that may be the issue is with your input files. Share the first few and last few characters from the file. You might need to specify one of the options:

Thanks for your suggestions - I still couldn’t get it to work. I need to do the assignment, so I’m just working with one of the sample databases. I’ll probably try and get to the bottom of my ‘mongoimport’ issue later, with some different JSON files.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.