我有一个图表,其中包含无限级别的类别和子类别以及子子类别。如何在一个密码查询中获取所有这些分层数据?
我目前有这个查询:
START category=node:categoryNameIndex(categoryName = "category")
MATCH path = category <- [rel:parentCategory] - subcategory
RETURN category, collect(subcategory);
这给了我以下结果:
| category | collect(subcategory) |
==> +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
==> | Node[26]{categoryName:"Test2",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"} | [Node[25]{categoryName:"Test1",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"}] |
==> | Node[1]{categoryName:"Test1",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"} | [Node[26]{categoryName:"Test2",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"},Node[2]{categoryName:"Test2",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"}] |
我正在使用 node-neo4j。我将以 json 格式举例说明我想要的内容。
[{
"categoryName": "Test2",
"categoryDescription": "testDesc",
"imageUrl": "testUrl",
"children": [{
"categoryName": "Test1",
"categoryDescription": "testDesc",
"imageUrl": "testUrl",
"children" : [{
"categoryName": "Test1",
"categoryDescription": "testDesc",
"imageUrl": "testUrl"
}]
}]
}]
我这可能吗?我知道我总是可以通过编程或使用多个查询来完成它。但如果它可以在单个查询中完成,那将非常有帮助。