Couchbase N1QL要退货并计数

时间:2019-07-15 17:11:31

标签: couchbase n1ql

试图弄清楚如何使我的沙发床返回一个像这样的对象:

{
  items: [],
  totalItemsCount: T<number>,
}

我的选择的格式如下:

SELECT  a.*, (  SELECT COUNT(*) FROM table b WHERE b.environment = "test" AND b.DocType = "GM360.User") as Count 
FROM table a WHERE a.environment = "test" 
AND a.DocType = "Moderator.User" 
limit 5 offset (5 * (1 -1) )

结果如下:

[
  { Accounts: [], UserId: 1,  Count: 199 },
  { Accounts: [], UserId:, 2, Count: 199 },
]

1 个答案:

答案 0 :(得分:4)

以下查询给出了您期望的结果对象。如果那还不能更清楚地说明问题,那么。

State

OR

SELECT (SELECT RAW a
        FROM table AS a
        WHERE a.environment = "test" AND a.DocType = "Moderator.User") AS items,
       (SELECT RAW COUNT(1)
        FROM table b
        WHERE b.environment = "test" AND b.DocType = "GM360.User")[0] AS totalItemsCount;