1
我有一個嵌套的has_many關係,我試圖映射到json結果。嵌套has_many關係在密碼
從博客下面的例子顯示我想要做的事情,但它不是嵌套
MATCH (a:Person { name: "Andres" })-[:FATHER_OF]->(child)
RETURN
{name:a.name, kids:collect(child.name)} as document
我想的卻是這樣的
MATCH (a:Person { name: "Andres" })-[:FATHER_OF]->(child)-[:has_read]->(book)-[:has_chapter]->(chapter)
RETURN
{name:a.name, kids:collect({"name":child.name, has_read:collect(book)})} as document
在這種情況下,我想返回像這樣的結構的json對象:
{
"name": "Andres"
"kids": [
{
"name":"Bob"
"has_read": [
{
"name":"Lord of the Rings",
"chapters": ["chapter1","chapter2","chapter3"]
},
{
"name":"The Hobbit",
"chapters": ["An unexpected party","Roast mutton"]
}
]
},
{
"name":"George"
"has_read": [
{
"name":"Lord of the Rings",
"chapters": ["chapter1","chapter2","chapter3"]
},
{
"name":"Silmarillion",
"chapters": ["chapter1","chapter2"]
}
]
}
]
}
「收集({名孩子。姓名,has_read:books})「我以前沒有看到過這個收集語法。它記錄在任何地方嗎? –
@BobB - http://neo4j.com/docs/stable/query-aggregation.html#aggregation-collect – OpenDataAlex