Search code examples
mongodbfiwarefiware-orion

FIWARE Orion: how to add creDate and modDate to notification from orion?


I am trying to use subscribeContext and notify (see link https://fiware-orion.readthedocs.io/en/master/user/walkthrough_apiv1/index.html#ngsi10-standard-operations)

As in mongodb, have creDate and modDate attribute, but in notifyContextRequest payload does not have these two attributes.

It's possible to include creDate and modDate attribute to notifyContextRequest payload?

Is there any way to get these attribute using Orion method?

Please see below for more details: A row an mongodb:

{
    "_id" : {
        "id" : "sb1_dv1_5",
        "type" : "Call",
        "servicePath" : "/"
    },
    "attrNames" : [ 
        "status", 
        "type", 
        "to"
    ],
    "attrs" : {
        "status" : {
            "type" : "string",
            "creDate" : 1488876118,
            "modDate" : 1488876118,
            "value" : "open",
            "mdNames" : []
        },
        "type" : {
            "type" : "string",
            "creDate" : 1488876118,
            "modDate" : 1488876118,
            "value" : "video",
            "mdNames" : []
        },
        "to" : {
            "type" : "string",
            "creDate" : 1488876118,
            "modDate" : 1488876118,
            "value" : "police",
            "mdNames" : []
        }
    },
    "creDate" : 1488876118,
    "modDate" : 1488876118
}

Thank you so much.


Solution

  • If you are using one of the most recent Orion versions (I think that it was introduced in 1.5.0) you can use dateCreated and dateModified in the metadata field within notification at subscription creation, eg:

    POST /v2/subscriptions
    
    {
       ...
       "notification": {
          ...
          "metadata": [ "dateCreated", "dateModified", "*" ]
          ...
       }
       ...
    }
    

    Check section "Filtering out attributes and metadata" abd "System/builtin Metadata" at NGSIv2 latest specification for more detail.

    UPDATE: the above refers to the dateCreated and dateModified metadata (to have creation and modification date for attrinutes). If you want dateCreated and dateModified attributes (to have creation and modification date for the entity as a whole) it is added in a similar way, but using attrs field, eg:

    POST /v2/subscriptions
    
    {
       ...
       "notification": {
          ...
          "attrs": [ "dateCreated", "dateModified", "*" ]
          ...
       }
       ...
    }
    

    Check section "Filtering out attributes and metadata" abd "System/builtin Attributes" at NGSIv2 latest specification for more detail.