问题
I'm using Orion to store context information, and among all the entity attributes there are two that are time specific:
- updated_at
- created_at
How can I store this? Is there a timestamp or datetime attribute type in Orion?
回答1:
You can use attribute type date
to store dates, as described in NGSIv2 specification section "Special attribute types". For example, you could create the following entity:
POST /v2/entities
{
"id": "myEntity",
"type": "myType",
"updated_at": {
"value": "2017-06-17T07:21:24.00Z",
"type": "date"
},
"created_at": {
"value": "2017-06-17T07:21:24.00Z",
"type": "date"
}
}
Note that (at least in the newest Orion version, 0.28.0) precision is seconds. In order words, you can create/update with 2017-06-17T07:21:24.238Z
but you will get 2017-06-17T07:21:24.00Z
.
Note also that Orion manages automatically creation and modification dates for entities, i.e. your client doesn't need to manage them. In order to retrieve entity creation and/or modification use them in the options
URI param, as described in NGSIv2 specification section "Virtual attributes". For example:
GET /v2/entities/myEntity?options=dateCreated,dateModified
来源:https://stackoverflow.com/questions/36176405/how-do-i-store-timestamp-or-datetime-in-orion