Unable to Import people json - Laba1.1

I have the mongodb installed and i have saved the people json in my local directory under C:\Users\preddyd\M001\people
Now, I go to cmd prompt and cd to the above path
I ran mongo and it runs ok
i am trying to use load(“people.json”) and it fails as below
MongoDB Enterprise > load(“people.json”)
2019-11-01T03:48:51.728-0800 E QUERY [js] SyntaxError: unexpected token: ‘:’ :
2019-11-01T03:48:51.734-0800 E QUERY [js] Error: error loading js file: people.json :

I am also trying the import command but i get the below error

MongoDB Enterprise > mongoimport -help
2019-11-01T03:49:16.722-0800 E QUERY [js] ReferenceError: mongoimport is not defined :

A .json file is a data file, you do not use load. The documentation for load is at https://docs.mongodb.com/manual/reference/method/load/. What you want to do with a .json file is to import it with the command https://docs.mongodb.com/manual/reference/program/mongoimport/

1 Like

Indeed mongoimport is the solution.

Please ensure that :

  • the mongoimport command exists on your system : its location is in the same folder (bin) as the mongo command, which seems to be present on your computer
  • your MongoDB installation bin directory is in your Windows Environment Variables (the MongoDB courses explain how to do this, but you can also search on the Internet). If you can’t do this, for exemple if your Windows profile rights are unsufficient, you can go in the MongoDB bin folder using the “cd <dir>” command in your CMD window

For example, an installation bin directory could be : C:\Program Files\MongoDB\Server\4.2\bin

Good luck !

1 Like

A lot of hints given already:

1 Like

Just in case it is not clear enough, what 007_jb tells you is that mongoimport is not to be used inside the mongo shell.


here is python script to import data if you don’t have mongoimport tool: Python script to import data if no mongoimport