I'm trying to import a csv file into MongoDB and running into "Unexpected Identifier" error.
mongoimport –-db projectexperiment -—collection structured_1000 --type csv --file /dataset/structured/structured_1000.csv --headerline
Am quite new to MongoDB and was wondering if some one could point me in the right direction
You need to run mongoimport from the terminal. Assuming you are using Windows, you need to start a DOS prompt (cmd) go to the bin directory of your mongodb installation and run your monogimport command:
C:\mongodb\bin>mongoimport –-db projectexperiment -—collection structured_1000 --type csv --file /dataset/structured/structured_1000.csv --headerline
Related
trying to import a csv file into my MongodbAtlas collection.
This is the command I run in terminal:
mongoimport --uri mongodb+srv://Jfreundlich01:<PASSWORD>#seir-cluster.sclij.mongodb.net/Optimizer --collection Players --type csv --file "Seed.csv"
Where Seed.csv is a file on my desktop.
When I click return it goes to a new line in my terminal but nothing happens.
After I run that line, if I type mongoimport --help or --version or any of those options, I get:
no such file or directory: <part of my password>#seir-cluster.sclij.mongodb.net/Optimizer
But if I close the terminal, open a new terminal and run mongoimport --version i get:
mongoimport version: 100.6.0
Any help/guidance would be greatly appreciated!
Thanks
I am following the example given on MongoDB's website here, but I am running into trouble when trying to import sample data.
When running the command
mongoimport --db test --collection restaurants --drop --file primer-dataset.json
I get the error:
Failed: open primer-dataset.json: The system cannot find the file specified
The problem is, I am not sure what directory MongoDB expects this file to be in. I tried placing it in data/db, but that did not work. Note that I am only using default settings.
I know this is a somewhat trivial question and I feel stupid for asking it but I can not find documentation on this anywhere. Where is MongoDB expecting import files?
MongoDB expects the file to be in the directory from where you are running the command mongoimport.
If you place your file under data/db then set mongodb path as global environment variable and execute the command from data/db directory.
Additionally if you have security enabled for your mongodb then you need to execute command as below
mongoimport --username admin --password password --db test --collection restaurants --drop --file primer-dataset.json
here admin is the user authorized to perform db operations for test database and restaurants is the collection name.
For Windows!
Save file using notepad++ in .json format at MongoDB/bin where mongoimport command is present.
Simple notepad has trouble doing it.
It happened to me as well. The issue was that though the file was visible as restaurants.json actually the file was restaurants.json.json (since saved in JSON format). The issue was resolved after properly changing the name.
i have trouble like you, check you path to file, mongoimport.exe and your file may be stay in another folders.
use mongoimport -d test1 -c restaraunts companies.json for import to mongodb.
Check the filename extension, and make sure it's a ".json" file;
After this I successfully run the
mongoimport --db test --collection restaurants --drop --file [path\to\Json file]
command;
In my case, I removed the --drop parameter and it worked perfectly. I guess, it is throwing this error:
Failed: open paht/file-name.json: The system cannot find the file specified.
because the collection it wants to drop is not available, because I have not created any before.
you must copy your json file into C:\Windows\System32 and write this command on cmd:
mongoimport --db test --collection mongotest --type json --file yournamefile.json
I have installed mongoDB2.4 installed in my windows 7 os. I am new to mongoDB. I would like to import data from a csv file into the database. I have used the mongoimport command but it shows:
Javascript execution failed: Syntax error: Unexpected identifier
my command in mongo shell was:
mongoimport --db mentalhealth --collection bidyut --type csv --file \Users\Adrian\Desktop\Data_sorted.csv
PLEASE kindly provide an answer.
I have a csv file containing following data and want to import it in mongodb
ID;"AdmissionID";"SeatNo";"RegistrationNo";"ResultDate";"ResultStatusId"
1;12;"2323";"23";07-05-2013;1
2;23;"35";"32";10-05-2013;5
this data is to be imported to mongodb 2.2. I'm using following command:
mongoimport -d test -c exam --type csv --headerline <f:\exam.csv
when used i get following error
SyntaxError: missing ; before statement (shell):1
please help me to find out the error
This should do the trick easily. More HERE.
mongoimport -d mydb -c collectionName --type csv --file myfile.csv --headerline
Your problem is the <f:\exam.csv bit, which is not properly escaped by the way it looks
> --headerline
> If using “--type csv” or “--type tsv,” use the first line as field names. Otherwise, mongoimport will import the first line as a distinct
> document.
Please try this line of code
C:\Program Files\MongoDB\Server\3.2\bin>mongoimport -d pravin -c FOC --type csv
--file D:\Script\ImportData\FOC.csv --headerline
2016-08-10T15:42:38.685+0530 connected to: localhost`enter code here`
2016-08-10T15:42:38.758+0530 imported 13 documents
I solved by opening the .csv file in Excel (File -> Options -> advanced) then unchecking the box "uses system separation" and then removing the comma from the box below and then saving again in .csv.
So there will not be any commas in the .csv file and the formatting of JSON in MongoDB will be right.
Run mongoimport from the system command line, not the mongo shell.
Ref - https://docs.mongodb.com/manual/reference/program/mongoimport/
I tried mongo import like this
mongoimport -d test -c foo importfile.json
mongoimport --host localhost --db local --collection lecturer --type json --file temp.json --headerline --upsert
and I've got same error message "Syntax Error: missing ; before statement (shell):1"
what's wrong with my code & how to import if my data stored in C:\Documents and Settings\User\Desktop ?? please help, thank's in advance
mongoimport is intended to run in command prompt and not in the mongo shell. Try exiting out of the shell and running the command.
One solution is:
First, in cmd, change to the directory containing mongoexport.exe file, then type your command.
C:\Program Files\MongoDB\Server\3.2\bin> .\mongoexport.exe -d foo -c bar -o output.json
mongoimport is to be run on the terminal and not inside the mongo shell. To run mongoimport in terminal, you will need to install the same. On ubuntu, you can do :
apt-get install mongo-tools
Hope this helps :)
I had the same problem and was able to figure it out after a brief struggling and googling.
1. Navigate to the bin directory in command prompt
(cd c:..\bin)
2. Run the mongoimport command but you have to specify the full path of your json file.
That solves the problem
try to use CSV is a good.
mongoimport -d mydb -c things --type csv --file locations.csv --headerline --upsert
You can convert by ms excel.
Open the "Mongo/Server/3.4/bin" folder of mongo db in another command window and try again.It Will work.
Open a new terminal or command prompt within the location of the file you want to import and it should work. It will not work on MongoDB shell