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
If you have CSV files (or TSV files - they're conceptually the same) to import, use the --type=csv or --type=tsv option to tell mongoimport what format to expect. Also important is to know whether your CSV file has a header row - where the first line doesn't contain data - instead it contains the name for each column.
On the File menu, click Import. In the Import dialog box, click the option for the type of file that you want to import, and then click Import. In the Choose a File dialog box, locate and click the CSV, HTML, or text file that you want to use as an external data range, and then click Get 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.
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
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