select 嵌套子文档 Couchbase 中的特定字段
select a particular field from nested subdocuments Couchbase
我在 couchbase 存储桶中有具有这种结构的文件:
"name": {
"grandfather": {
"parent1": {
"child1": [
{
.....
"uid": "value1",
},
{
"uid": "value2",
}
],
},
"parent2": {
"child2"
[
{
"uid": "value3",
}
],
}
}
}
我需要一个 returns
的查询
{
{
"uid": "value1",
},
{
"uid": "value2",
}
{
"uid": "value3",
}
}
.. 直觉上是这样的:
select grandfather.*.*.uid from name;
但是这个不行。如果有人能帮忙,谢谢
所有文档
WITH doc AS ( { "grandfather": { "parent1": { "child1": [ { "uid": "value1" }, { "uid": "value2" } ],
"child2": [{ "uid": "value3"}]
},
"parent2": { "child1": [ { "uid": "value4" }, { "uid": "value5" } ],
"child2": [{ "uid": "value6"}]
}
}
})
SELECT RAW c1
FROM doc AS a
UNNEST OBJECT_VALUES(a.grandfather) AS p
UNNEST OBJECT_VALUES(p) AS c
UNNEST c AS c1;
每个文档一个条目
WITH doc AS ( { "grandfather": { "parent1": { "child1": [ { "uid": "value1" }, { "uid": "value2" } ],
"child2": [{ "uid": "value3"}]
},
"parent2": { "child1": [ { "uid": "value4" }, { "uid": "value5" } ],
"child2": [{ "uid": "value6"}]
}
}
})
SELECT ARRAY_FLATTEN(ARRAY (ARRAY cv FOR cn:cv IN pv END) FOR pn:pv IN a.grandfather END,3) AS names
FROM doc AS a;
我在 couchbase 存储桶中有具有这种结构的文件:
"name": {
"grandfather": {
"parent1": {
"child1": [
{
.....
"uid": "value1",
},
{
"uid": "value2",
}
],
},
"parent2": {
"child2"
[
{
"uid": "value3",
}
],
}
}
}
我需要一个 returns
的查询{
{
"uid": "value1",
},
{
"uid": "value2",
}
{
"uid": "value3",
}
}
.. 直觉上是这样的:
select grandfather.*.*.uid from name;
但是这个不行。如果有人能帮忙,谢谢
所有文档
WITH doc AS ( { "grandfather": { "parent1": { "child1": [ { "uid": "value1" }, { "uid": "value2" } ],
"child2": [{ "uid": "value3"}]
},
"parent2": { "child1": [ { "uid": "value4" }, { "uid": "value5" } ],
"child2": [{ "uid": "value6"}]
}
}
})
SELECT RAW c1
FROM doc AS a
UNNEST OBJECT_VALUES(a.grandfather) AS p
UNNEST OBJECT_VALUES(p) AS c
UNNEST c AS c1;
每个文档一个条目
WITH doc AS ( { "grandfather": { "parent1": { "child1": [ { "uid": "value1" }, { "uid": "value2" } ],
"child2": [{ "uid": "value3"}]
},
"parent2": { "child1": [ { "uid": "value4" }, { "uid": "value5" } ],
"child2": [{ "uid": "value6"}]
}
}
})
SELECT ARRAY_FLATTEN(ARRAY (ARRAY cv FOR cn:cv IN pv END) FOR pn:pv IN a.grandfather END,3) AS names
FROM doc AS a;