0
mongoimport --db test --collection collection1 --file c:/test.json

I got SyntaxError: Unexpected identifier when executing the above command.

What is the problem of this script?

Thank you very much

Chaitanya Bapat
  • 3,381
  • 6
  • 34
  • 59
Jason Z
  • 265
  • 1
  • 6
  • 12
  • 1
    possible duplicate of [Importing JSON file using mongimport, keep getting \`unexpected identifier\`?](http://stackoverflow.com/questions/16500127/importing-json-file-using-mongimport-keep-getting-unexpected-identifier) – t.niese Apr 03 '15 at 17:47

2 Answers2

4

I had the same issue when i tried to import json file from MongoDB Shell.
You can query it from command prompt.
My directory stucture:

C:\Program files\MongoDB\Server\3.0\bin\mongoimport.exe  
C:\filename.json

e.g.

C:\Program Files\MongoDB\Server\3.0\bin> ./mongoimport --db dbname --collection collection_name C:\filename.json  

Output should be:

2015-08-18T09:34:25.617-0700    connected to: localhost
2015-08-18T09:34:25.632-0700    imported 10 documents

Now switch back to MongoDB Shell:

 C:\Program Files\MongoDB\Server\3.0\bin> ./mongo
 use dbname
 db.collection_name.find().pretty()
H. U.
  • 627
  • 1
  • 10
  • 25
0

One problem here could be that you do not have your PATH set properly on your computer. If you are using Windows 10 -

  • go to Control Panel and to System Security System
  • then find the Advanced System Settings on the left panel.
  • A window will pop up - at the bottom will be a button for Environment Variables
  • Click that and the new window will have two panels of Variables
  • find and select Path in both user / system panels - click edit and add a new path with the path to the MongoDb exe
  • example : C:\Program Files\MongoDB\Server\3.6\bin