如何将AQL的所有结果合并到具有自定义属性的单个文档中 [英] How to merge all results of AQL into single document with custom properties
本文介绍了如何将AQL的所有结果合并到具有自定义属性的单个文档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个AQL查询遍历图,该图始终应从一组唯一的集合中返回固定数量的文档. 因此,每个集合只会出现一次,并且只有一个文档.
I have an AQL query traversing graph that always should return a fixed amount of documents from a unique set of collections. So each collection will occur only once and with one document only.
我希望将它们全部合并到一个文档中,该属性反映文档的集合名称.
I wish to merge them all into a single document under properties that reflects document’s collection name.
查询简单:
FOR v IN ANY "vertex/key" edge_collection RETURN v
将样本结果返回为:
[
{
"_key": "123",
"_id": "foo/123",
"_rev": "_WYhh0ji---",
"foo_attribute": "lorem impsum"
},
{
"_key": "456",
"_id": "bar/456",
"_rev": "_WYhh2ny---",
"bar_attribute": "dolor sit amet"
}
]
我希望这样:
[
{
"foo": {
"_key": "123",
"_id": "foo/123",
"_rev": "_WYhh0ji---",
"foo_attribute": "lorem impsum"
},
"bar": {
"_key": "456",
"_id": "calendar/bar",
"_rev": "_WYhh2ny---",
"bar_attribute": "dolor sit amet"
}
}
]
推荐答案
- 为了从文档中获取集合名称,请使用
PARSE_IDENTIFIER
函数分别给出文档的集合名称和键 - 使用方括号理解来生成动态文档属性
- 简单地合并查询结果
- In order to get collection name from document use
PARSE_IDENTIFIER
function that gives document’s collection name and key separately - Use square brackets comprehension to generate document property dynamically
- Simply merge result of the query
示例:
RETURN MERGE(
FOR v IN ANY "vertex/key" edge_collection
RETURN {[PARSE_IDENTIFIER(v).collection]: v}
)
这篇关于如何将AQL的所有结果合并到具有自定义属性的单个文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文