【问题标题】:N1QL Array Query for where condition to check inner elamentN1QL 数组查询检查内部元素的条件
【发布时间】:2023-03-09 22:45:02
【问题描述】:

我有如下 JSON 格式

{
  "_id": "000fad10-b2de-11e6-92de-632a9b1d21d9",
  "_type": "Company",
  "status": 1,
  "transactions": [
    {
      "completed": 1,
      "currency": "USD",
      "date": "2015-12-01T18:30:00.000Z",
      "method": 0,
      "type": 0
    }
  ]
}

我想像下面的查询一样运行

select * from MyBucket where transactions.method in (0,3);

如何在 N1QL 中做到这一点??

【问题讨论】:

    标签: json node.js couchbase n1ql


    【解决方案1】:

    试试这个:

    SELECT * FROM MyBucket b UNNEST b.transactions t WHERE t.method in [0,3];
    

    保留这个cheatsheet

    【讨论】:

    • 我错过了 in 中的“[]”。使用您的查询,我总共得到 4 个 json。但我只有 3 个。在一个 json 中我有 2 个事务。
    • 无需 UNNEST:SELECT * FROM MyBucket WHERE transactions.method IN [0,3];
    • 你能看到这个问题吗?? stackoverflow.com/questions/40838443/…
    【解决方案2】:
    SELECT * FROM MyBucket WHERE ANY x IN transactions SATISFIES x.method in[1,0] END;
    

    我得到了答案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-09
      • 1970-01-01
      相关资源
      最近更新 更多