N1ql查询以处理日期时间方案

问题描述 投票:0回答:1

我有一个需要从学生文档中获取所有记录的场景:

  "fname": "abc",
  "timeOfAdmission": 1576042885166,
  "lname": "rawat",
  "studentId": "1"

其中,studentId是我们的documnetId。

是否可以使用N1ql执行这样的查询

select * from students where (CurrentTime - timeOfAdmission) > 3600000.

其中CurentTime,timeOfAdmission和3600000以毫秒为单位。

我们如何使用N1ql编写此查询?

couchbase n1ql spring-data-couchbase
1个回答
0
投票

您可以使用日期功能https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datefun.html#fn-date-now-millis

SELECT s.*
FROM students AS s
WHERE s.timeOfAdmission <  NOW_MILLIS() - 3600000;

CREATE INDEX ix1 ON students(timeOfAdmission);
© www.soinside.com 2019 - 2024. All rights reserved.