我的Couchbase文档数据库中有以下结构:
{
"documentType": "connection",
"id": "09690237-9ef5-4381-93dc-7312f7417f82",
"entities": [
{
"id": "8a282f31-5d6c-4741-909f-a84ef48571af",
"type": "item",
},
{
"id": "01f6a9eb-0d7e-4495-a90f-f96a38aef621",
"type": "group",
}
]
}
众多物品'存在于每个组'在数据库中。我想检索特定组ID的所有项目的列表。例如,如果" 01f6a9eb-0d7e-4495-a90f-f96a38aef621"提供我需要的东西:
[
"8a282f31-5d6c-4741-909f-a84ef48571af",
"9a282f31-5d6c-4741-909f-a84ef48571af",
...
]
然而,我得到了很多名为' entity'在单独的小结构中,我无法将它们组合在一起。这是我目前的N1QL查询:
select array entity.id for entity in entities.entities when entity.type = 'item' end as entity
from entities
where entities.documentType = 'connection'
and any entity within entities satisfies entity.id = '01f6a9eb-0d7e-4495-a90f-f96a38aef621'
and entity.type = 'group' end
我是N1QL的新手,所以也会有一些解释。
谢谢。
答案 0 :(得分:2)
dput(elements)
structure(list(var1 = c("Date", "9/22/2015", "9/22/2015", "9/22/2015",
"9/22/2015", "9/22/2015", "9/22/2015", "9/22/2015"), var2 = c("Time_hms",
"00:00:00", "00:00:24", "00:00:24", "00:01:42", "00:02:04", "00:02:35",
"00:03:02"), var3 = c("Event", "5", "1", "4", "7", "3", "2",
"4")), .Names = c("var1", "var2", "var3"), row.names = c(NA,
8L), class = "data.frame")