【问题标题】:Couchbase how to query an arrayCouchbase 如何查询数组
【发布时间】:2018-02-05 18:40:50
【问题描述】:

如果我有如下所示的 Couchbase 文档:

{
  "history": {
    "id": "123",
    "date": "today",
    "status_history": [
      {
        "code": "0",
        "message": "success",
        "status": "complete"
      }
    ],
    "other": "other"
  }
}

如果我想获取今天的所有文件,我可以执行 select * from 'my_bucket' where history.date = "today" 之类的操作

但是我怎样才能从数组结构中的 status_history 中获得类似状态的东西呢?

select * from 'my_bucket' where history.status_history. status?? = "complete"

【问题讨论】:

    标签: couchbase n1ql


    【解决方案1】:

    除了特定数组元素的[] 语法之外,如果您想确保任何元素(或所有元素)满足某些条件,还可以使用ANYALL。例如:

    select * from my_bucket 
    where any s in status_history satisfies s.status = 'complete' end;
    

    【讨论】:

      【解决方案2】:

      您可以使用[] 语法来寻址数组元素。

      例如:

      SELECT h.*
      FROM my_bucket h
      WHERE h.status_history[0].status = 'complete'
      

      【讨论】:

        猜你喜欢
        • 2018-07-19
        • 2017-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多