I am doing some tests to see how I can import a simple .csv file into mongodb but it mongodb keeps returning "0 objects imported. Here are my steps:
1) create a simple .csv file named "a4.csv" in mongodb/bin with 4 columns and 6 records:
Model Make Price Mileage
audi a5 500 500
mercedes cla 333 434
ford fusion 555 500
mazda miata 222 434
nissan 370z 111 500
porsche cayenne 333 434
2) Run import command:
./mongoimport -d test -c cars --type csv --file a4.csv --headerline
Output:
tins-MBP:bin tinzors$ ./mongoimport -d test -c cars --type csv --file a4.csv --headerline
connected to: 127.0.0.1
2015-02-11T12:23:11.656-0500 imported 0 objects
There's no error anything. Can someone help me? Thank you!
I think problem is in csv
file format
a4.csv file placed in mongodb bin folder
Model,Make,Price,Mileage
audi,a5,500,500
mercedes,cla,333,434
ford,fusion,555,500
mazda,miata,222,434
nissan,370z,111,500
porsche,cayenne,333,434
then
mongoimport -d test -c cars --type csv --file a4.csv --headerline
Output
D:\MongoDB\MongoDB 2.6 Standard\bin>mongoimport -d test -c cars --type csv --file a4.csv --headerline
connected to: 127.0.0.1
2015-02-11T23:15:20.631+0530 imported 6 objects
> db.cars.find()
{ "_id" : ObjectId("54db93a60259aeb2c15b851d"), "Model" : "audi", "Make" : "a5", "Price" : 500, "Mileage" : 500 }
{ "_id" : ObjectId("54db93a60259aeb2c15b851e"), "Model" : "mercedes", "Make" : "cla", "Price" : 333, "Mileage" : 434 }
{ "_id" : ObjectId("54db93a60259aeb2c15b851f"), "Model" : "ford", "Make" : "fusion", "Price" : 555, "Mileage" : 500 }
{ "_id" : ObjectId("54db93a60259aeb2c15b8520"), "Model" : "mazda", "Make" : "miata", "Price" : 222, "Mileage" : 434 }
{ "_id" : ObjectId("54db93a60259aeb2c15b8521"), "Model" : "nissan", "Make" : "370z", "Price" : 111, "Mileage" : 500 }
{ "_id" : ObjectId("54db93a60259aeb2c15b8522"), "Model" : "porsche", "Make" : "cayenne", "Price" : 333, "Mileage" : 434 }
Hope it helps.
So I THINK part of the issue is I created the file in Excel then saved it as a .csv file that that might have corrupted the file somehow. So I opened the original .csv file in a text editor (Sublime), copied the data into a brand new Sublime document and re-saved it as .csv and it worked!