Column mapping, data types and transformations

For Parse Server users, you must read the the section on importing CSV before reviewing this document. In most cases, this document will not apply for your use case.

If you do not specify the data types of the various columns, everything will be imported as a string. In some cases, this will be highly undesirable when you are importing numbers, geopoints arrays and so on.

The below example will provide details on how to specify the data types of the various columns, rename columns, create arrays etc.

# Consider the below csv file name,age,height,location,likes,address_line_1,address_city,address_zip,address_state,address_country menes,45,1.81,"43.6532,79.3832","rotisserie chicken|lemon meringue pie",89-86 NodeChef DR, Toronto,M5B2K3,Ontario,Canada # When imported to the database, the below output structure is required. { _id : <System generated MongoDB Id>, name : "menes", age : 45, height : 1.81, loc : [79.3832,43.6532], likes : ["rotisserie chicken", "lemon meringue pie"], address : { street : "89-86 NodeChef DR", city : "Toronto", zip : "M5B2K3", state : "Ontario", country : "Canada" } } # To generate the above structure, you will have to paste the below transformation logic into # the textbox provided under Optional data mapping and types { _id : { $objectid : 1 }, name : "name", age : { $toint64 : "age" }, height : { $todouble : "heighht" }, loc : { $togeopoint : "location" }, likes : { $split : "likes", by : "|" }, address : { street : "address_line_1", city : "address_city", zip : "address_zip", state : "address_state", country : "address_country" } }

How it works?

  • "_id : { $objectid : 1 }" - This logic means create a new field with name _id and populate it with a mongodb object Id.
  • "name : "name" - This logic means, there is a column in the CSV file with name "name", import this column as is.
  • "age : { $toint64 : "age" }" - This logic means, there is a column in the CSV file with name "age", import this column with the same name but cast the value to a 64 bit integer.
  • "loc : { $togeopoint : "location" }" - This logic means, there is a column in the CSV file with name "location", import this column however, rename it to "loc" instead and cast its value to a geopoint. The format for geopoints when importing a csv file is "latitude,longitude"
  • "likes : { $split : "likes", by : "|" }" - This logic means, there is a column with name "likes" in the CSV file, import this column with the same name, however split its values into an array. Split the values by the character "|". Note the pipe character above is only for demonstration purposes, it could have been any character at all.
  • street : "address_line_1" - Means, there is a column with name "address_line_1", import this column as is but rename to street under the address object.

Below is the list of all transformation functions and data types supported

ColumnName refers to the name of the column from the CSV file.

  • string{ $tolower : "columnName" }
  • string{ $toupper : "columnName" }
  • array{ $split : "columnName", by : "splitSequence" } Splits the string and returns an array
  • string{ $trim : "columnName" }
  • bsonid{ $objectId : 1 } Returns a new bson object id
  • boolean{ $toboolean : 1 } Returns a new bson object id
  • array{ $togeopoint : 1 } Returns an array with longitude at index 0 and latitude at index 1
  • int32{ $toint32 : "columnName" } Cast the input column to a 32 bit integer
  • int64{ $toint64 : "columnName" } Cast the input column to a 64 bit integer
  • double{ $todouble : "columnName" } Cast the input column to a double
  • date{ $toDate : "columnName" } Cast the input column to a date field
  • date{ $now : 1 } Returns a new date