Mongoimport not working

I’m CRUD operations episode-14, and I’m trying to import files to my mongodb compass (mongoimport --db mongo-exercises --collection courses – file exercise-data.json --jsonArray).

The first error I got is “mongoimport is not recognized as an internal or external command”.
That’s when I realized that I didn’t have that import module installed in my bin folder. Afterwards I downloaded the zip file for it:

Then I followed this tutorial on how to install it:

Ater installing the modules neccessary, I get another error in the terminal

“2021-01-29T17:21:35.122-0700 error parsing command line options: error parsing positional arguments: provide only one file name and only one MongoDB connection string. Connection strings must begin with mongodb:// or mongodb+srv:// schemes
2021-01-29T17:21:35.128-0700 try ‘mongoimport --help’ for more information”.

Here’s my bin:

mongo_bin

PLEASE HELP!

1 Like

I solved it; the last error was a syntax error as there was a space between the dashes and file. (-- file) should be (–file).

Also if anyone else is experiencing that import error: “mongoimport is not recognized as an internal or external command”, check the the 2 links I posted above.

Thank you so much you saved me !

Steps for windows if you hit this issue:

  1. Download MongoDB Command Line Database Tools | MongoDB
  2. Extract
  3. I copied the folder into C:\Program Files\MongoDB\ for convenience
  4. Edit your Environment Variables > System > PATH > New > (C:\Program Files\MongoDB\mongodb-database-tools-windows-x86_64-100.6.1\bin). Save.
  5. Close and re-open VSCode to be able to pick up the new Path item.

Should be able run the mongoimport command now

For anyone else on 14 Exercise 1, I was successful in executing this long command:

mongoimport --db mongo-exercises --collection courses --drop --file exercise-data.json --jsonArray

The trick is to make sure you navigate into the exercise folder. That’s because the json file (exercise-data.json) lives in there, not in the root.

I don’t see a solution for Mac users

You saved my life as well