Optional Transformations

You can change the shape of the incomming JSON data by eliminating fields, adding new data fields as well as changing the shape of the JSON structure

# Consider the below JSON structure { "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters": { "batter": [ { "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" } ] }, "topping": [ { "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" } ] } # At insert time the below JSON structure is desired. { _id : ObjectId("a68e0f5796032530f6490000"), type : "donut", name : "cake", toppings : [ "None", "Glazed", "Sugar" ], createdAt : ISODate("...") } # Use the below transformation to accomplish this { _id : { $objectid : 1 }, type : 1, name : 1, toppings : [ "topping.type" ], createdAt : { $now : 1 } }

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
  • 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