N1QL:直接在数组上使用 select

N1QL: Using select directly on arrays

我在查询数组中的对象时遇到问题。

我有这个示例文档

{
  ...
  status: 'active',
  current: { ... },
  history: [
    {
      id: '73bae187-1101-4fb3-a71a-2bbf90026eb3',
      date: '2017-03-28T09:32:22.884Z',
      content: 'This is second content'
    },
    {
      id: 'd6a6c63d-42db-4ef5-88e9-616cfe539a57',
      date: '2017-03-25T09:32:22.884Z',
      content: 'This is first content'
    },
    {
      id: '3fbdb846-2b55-4ff8-8960-86997ef31556',
      schedule: '1970-01-01T00:00:00.000Z',
      content: 'This is a very old content'
    }
  ]
}

我想直接从 历史数组 子文档中查询,我想在其中应用日期过滤器。

是否可以在 n1ql 中检索仅包含满足条件的对象的历史数组?

我可以应用一个限制来控制数组中返回对象的数量吗?

我尝试了一些使用拼接的查询 [0:],其中 limit 是一个输入,但当 limit 大于数组大小时则不起作用。

感谢您的帮助。

尝试以下任一方法:

SELECT h[0:least(ARRAY_LENGTH(h), $arraylimit)] As h FROM default As d
LET h = ARRAY v FOR v IN d.history WHEN v.id  IN  [ 'xyz', 'pqr'] END;

或者:

SELECT h[0:least(ARRAY_LENGTH(h),$limit)] As h (SELECT ARRAY_AGG(h) As h 
FROM default As d UNNEST d.history As h WHERE h.id IN  [ 'xyz', 'pqr'] GROUP BY d) As q;