Using your sample data, saved into a file called csv1.csv
:
"denis","omeri","21","Tirana","1","http:/google.com","m"
"olgert","llojko","20","Prrenjas","2","http:/facebook.com","m"
I ran the following command line (split for readability here, with made-up field names):
mongoimport --db test
--collection things
--type csv
--fields First,Last,Visits,Location,Number,Url,Letter
--file d:\temp\csv1.csv
And it imports successfully:
connected to: 127.0.0.1
Thu Mar 28 07:43:53.902 imported 2 objects
And in the things
DB:
> db.things.find()
{ "_id" : ObjectId("51543b09d39aaa258e7c12ee"),
"First" : "denis", "Last" : "omeri", "Visits" : 21,
"Location" : "Tirana",
"Number" : 1, "Url" : "http:/google.com", "Letter" : "m" }
{ "_id" : ObjectId("51543b09d39aaa258e7c12ef"),
"First" : "olgert", "Last" : "llojko", "Visits" : 20,
"Location" : "Prrenjas",
"Number" : 2, "Url" : "http:/facebook.com", "Letter" : "m" }
(I couldn't get the header row option working in 2.4 for CSV files for some reason, but the option of specifying the fields on the command-line works as well. You can also use a file that contains just the field names by using the fieldFile
command line option)