AQL how to collect documents into arrays under their collection name?

北战南征 提交于 2019-12-24 00:42:43

问题


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 asked what if the query returns many documents of the same collection?


回答1:


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
})
  • 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


来源:https://stackoverflow.com/questions/48971984/aql-how-to-collect-documents-into-arrays-under-their-collection-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!