Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoimport syntaxerror unexpected identifier

Tags:

json

mongodb

Following the Getting started with MongoDB tutorial at

https://docs.mongodb.org/getting-started/node/import-data/

Trying to import the example database using the given code

mongoimport --db test --collection restaurants --drop --file primer-dataset.json

I get

2015-07-09T21:52:17.396+1200 E QUERY    SyntaxError: Unexpected identifier

I am running this in a bash shell with mongod running in another shell. I have tried copying the data several times in case it was a problem with the json file, and even substituting the data with a very simple json file but the problem persists. Can someone help, please.

like image 716
metarzan Avatar asked Jul 09 '15 10:07

metarzan


People also ask

What is Mongoimport?

The mongoimport command is used to import your content from an extended JSON, CSV, or TSV export created by mongoexport.

How do I restore a JSON file in MongoDB?

Open the Import Wizard. Then, choose JSON as the import format and click OK. Click on + to add JSON source documents, – to remove them, or the clipboard icon to paste JSON data from the clipboard. Here we will add the JSON source document, Rainfall-Data.

How do I import a JSON file into MongoDB?

To import JSON file you need to follow the following steps: Step 1: Open a command prompt and give command mongod to connect with MongoDB server and don't close this cmd to stay connected to the server. Step 2: Open another command prompt and run the mongo shell. Using the mongo command.


1 Answers

You command is correct. Use it from the terminal and not inside the mongo shell. However, I would make a small tweak to your mongoimport as below just to make it generic: On the terminal :

mongoimport --db test --collection restaurants --drop --file /<complete-path>/primer-dataset.json

So, if file is in /myimports folder then it would be :

mongoimport --db test --collection restaurants --drop --file /myimports/primer-dataset.json
like image 93
anish Avatar answered Sep 28 '22 11:09

anish