gpt4 book ai didi

couchbase - 从嵌套的子文档 Couchbase 中选择特定字段

转载 作者:行者123 更新时间:2023-12-05 03:26:19 27 4
gpt4 key购买 nike

我在 couchbase 存储桶中有具有这种结构的文件:

    "name": {
"grandfather": {
"parent1": {
"child1": [
{
.....
"uid": "value1",
},
{
"uid": "value2",
}
],
},
"parent2": {
"child2"
[
{
"uid": "value3",
}
],
}
}
}

我需要一个返回的查询

{
{
"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 - 从嵌套的子文档 Couchbase 中选择特定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71757702/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com