在 ArangoDB 连接查询方面需要一些帮助。我有如下文档,其中 User 包含嵌套对象中的 Group 集合键(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
asArray
但需要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" }]
}
}
您的帮助将不胜感激!