AQL如何将文件以其收集名称收集到数组中? [英] AQL how to collect documents into arrays under their collection name?

查看:83
本文介绍了AQL如何将文件以其收集名称收集到数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

回答了先前的问题,该指南显示了如何使用其集合名称来收集文档,但是该查询存在明显的限制每个集合仅返回一个文档.

In answer to previous questions was shown how to collect documents under their collection names but there was a clear constraint that query returns only one document for each collection.

@CoDEmanX问查询是否返回相同集合的许多文档?

@CoDEmanX asked what if the query returns many documents of the same collection?

推荐答案

将不得不重做查询以使用聚合:

Will have to rework query to use aggregation:

FOR doc IN ANY "vertex/key" edge_collection
COLLECT collection = PARSE_IDENTIFIER(doc).collection INTO collected
RETURN MERGE({
    [collection]: collected[*].doc
})

  • 按集合名称COLLECT collection = PARSE_IDENTIFIER(doc).collection INTO collected
  • 对文档进行分组
  • 以收集名称作为属性的表单文档,将收集的文档数组作为值{ [collection]: collected[*].doc }
  • 将结果合并到单个文档中
    • Group documents by their collection name COLLECT collection = PARSE_IDENTIFIER(doc).collection INTO collected
    • Form document with collection name as property and array of collected documents as value { [collection]: collected[*].doc }
    • Merge results into single document
    • 这篇关于AQL如何将文件以其收集名称收集到数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆