简体   繁体   English

如何处理ArangoDB / AQL中的过期数据

[英]How to handle expired data in ArangoDB/AQL

I have a collection containing session data with a time to live flag. 我有一个包含会话数据的集合,其中包含生存时间标志。 I want to use AQL to query the session data, but I need to make sure that only "live" session are returned. 我想使用AQL来查询会话数据,但我需要确保只返回“实时”会话。 Is it possible to restrict a query based on the the time to live attribute. 是否可以根据生存时间属性限制查询。

Example entry is 示例条目是

  {
    user: "marc",
    sessionData: {},
    expires: 1403678241
  }

AQL: AQL:

FOR u IN users FILTER u.user == "marc" return u

should return the user only if expiry is not reached. 只有在未达到到期时才应返回用户。

you can use the DATE_NOW() function in AQL to retrieve the timestamp for "now". 您可以使用AQL中的DATE_NOW()函数来检索“now”的时间戳。 To convert it into something readable, you could use DATE_ISO8601(DATE_NOW()). 要将其转换为可读的内容,可以使用DATE_ISO8601(DATE_NOW())。 This requires ArangoDB 2.1 or higher. 这需要ArangoDB 2.1或更高版本。

Please note that the above work with UTC / Zulu times, without adjustment for DST or timezones. 请注意上述工作使用UTC / Zulu时间,无需调整DST或时区。

You can than use DATE_NOW in your queries as follows 您可以在查询中使用DATE_NOW,如下所示

FOR u IN users FILTER u.user == "..." and u.expires >= DATE_NOW() return u

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM