Search code examples
jsonmongodbmongoimport

SyntaxError: Unexpected identifier while importing JSON file in MongoDB


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


Solution

  • 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()