Search code examples
kaa

mongodb Log Appender - optional field saving structure to MongoDB (Kaa 0.10.0)


I am using Kaa 0.10.0 and I have defined Log schema and created a MongoDB log appender. My question is when I upload a log record by client and save it to MongoDB by log appender, the optional field (driverLicenseNo, e.g.) json format would be like as below.

{
  "event" : {
      "driverLicenseNo" : {
            "string" : "310103198702092345"
        }
    }
}

or if value is null,

{
  "event" : {
      "driverLicenseNo" : null
    }
}

My expectation is

{
  "event" : {
      "driverLicenseNo" : "310103198702092345"
    }
}

or if value is null

{
  "event" : {
      "driverLicenseNo" : null
    }
}

Is there any configuration can be set to get the MongoDB json format as expected? Thanks!

Xiangfeng Qi


Solution

  • The optional field attribute (boolean, false by default) determines whether or not the field in the record is optional. Internally, Kaa translates optional fields into union fields with the null type at the top of the list. For more information, see Automatic generation of records. If there is an optional union field, Kaa automatically puts null at the top of the types list in the union definition. You can find this description in documentation.