How do I store timestamp or datetime in Orion?

笑着哭i 提交于 2020-01-06 03:25:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!