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.
The mongoimport command is used to import your content from an extended JSON, CSV, or TSV export created by mongoexport.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With