Import semicolon-delimited CSVs into the MongoDB database

I am just trying to import a CSV file (with semicolon; delimiter) into a MongoDB database. I managed to import using mongoimport -d mydb -c things --type csv --file files.csv --headerline, but the result is not what I expect. Files have the following form:

And I get the following result:

But I want something like:

{

   "_id": ObjectId("57b6e2654bf4a357b679305"),

   "geom_x_y" : "48.87792844925 , 2.3664591564",

   "circonfere" : "25.0",

   "adresse" : "PARIS 10E ARRDT - QUAI DE JEMMAPES",

   "hauteurnm" : "5.0",

   "espece" : "Acer platanoides",

   "varieteouc" : "'Schwedleri'",

   "dateplanta" : "31/12/2014"

}
+5
source share
1 answer

mongoimport, unfortunately, does not allow you to specify your separator character. But it automatically works with tabs as well as commas. If you know that you will never have tabs at your input, you can replace all semicolons with tabs and then import correctly.

tr ";" "\t" < file.csv | mongoimport --type tsv ...
+14
source

Source: https://habr.com/ru/post/1651823/


All Articles