需要一些关于ArangoDB联接查询的帮助。我有类似以下的文档,其中用户包含嵌套对象(groups)
中的组集合键。当我查询用户时,我需要联接组集合并更改响应。应该只执行WITH QUERY
。请检查下面给予的示例以获得更清晰的信息。
// User Collection
[
{
_key: "312121"
name: "Ash",
groups: {
"1": ["323223", ...etc], // Group collection _keys;
"2": ["342323", ...etc] // Group collection _keys;
}
}
]
// Group Collection
[
{
_key: "323223"
name: "Group 1"
},
{
_key: "313131"
name: "Group 2"
}
]
我尝试了以下查询:
LET user = DOCUMENT('users/312121')
LET groups_keys = ATTRIBUTES(user.groups) // ["1", "2"]
LET list = (
FOR key IN groups_keys
LET groups = (
FOR group_key IN user.groups[key] // user.groups["1"] and so on..
LET group = DOCUMENT(CONCAT('groups/', group_key))
RETURN { group_id: group._key, name: group.name }
)
RETURN { [key]: groups }
)
RETURN MERGE(user, { groups: groups })
它将groups
作为Array
返回,但需要将groups
作为Object
// Current Output:
{
_key: "312121"
name: "Ash",
groups: [ // <-- This should be object, not an array
{
"1": [{ _key: "323223", name: "Group 1" }]
},
{
"2": [{ _key: "313131", name: "Group 2" }]
}
]
}
但它应采用以下格式:
// Expected Output:
{
_key: "312121"
name: "Ash",
groups: { // <-- like this
"1": [{ _key: "323223", name: "Group 1" }],
"2": [{ _key: "313131", name: "Group 2" }]
}
}
您的帮助将不胜感激!
2条答案
按热度按时间vsaztqbk1#
使用
MERGE
MERGE
[docs]也接受数组参数:使用
ZIP
替代解决方案也可以使用
ZIP
[docs]:xqkwcwgp2#
试试这个,希望对你有帮助