Couchbase如何查询数组
如果我有这样的Couchbase文档:Couchbase如何查询数组,couchbase,n1ql,Couchbase,N1ql,如果我有这样的Couchbase文档: { "history": { "id": "123", "date": "today", "status_history": [ { "code": "0", "message": "success", "status": "complete" } ], "other": "other" } } 如果我想从今天获取所有文档,我可以执行类
{
"history": {
"id": "123",
"date": "today",
"status_history": [
{
"code": "0",
"message": "success",
"status": "complete"
}
],
"other": "other"
}
}
如果我想从今天获取所有文档,我可以执行类似于从'my_bucket'中选择*,其中history.date=“today”
但是如何从数组结构中的status_历史中获得类似status的内容呢
select * from 'my_bucket' where history.status_history. status?? = "complete"
您可以使用
[]
语法寻址数组元素
例如:
SELECT h.*
FROM my_bucket h
WHERE h.status_history[0].status = 'complete'
除了特定数组元素的
[]
语法外,如果要确保任何元素(或所有元素)满足某些条件,还可以使用ANY
和ALL
。例如:
select * from my_bucket
where any s in status_history satisfies s.status = 'complete' end;