切片查询输出的用户函数
User Function to slice query output
所以我正在对我的 Neo4j 数据库执行查询并返回预期的结果,尽管它的格式不同。我希望我的输出看起来像这样...
{"nodes":[
{"id":"James Gunn"},
{"id":"Zoe Saldana"},
{"id":"Bradley Cooper"},
{"id":"Vin Diesel"},
{"id":"Chris Pratt"},
{"id": "Guardians of the Galaxy",
"year":2014.0,
"director":"James Gunn",
"rating":8.1,
"runtime":121.0,
"description":"<Enter long desc here>",
"label":"Movie",
"actors":["Chris Pratt","Vin Diesel","Bradley Cooper","Zoe Saldana"],
"revenue":333.13,
"genres":["Action","Adventure","Sci-Fi"],
"name":"Guardians of the Galaxy",
"rank":1.0,
"votes":757074.0,
"metascore":76.0}],
"links":[
{"source":"Zoe Saldana","target":"Guardians of the Galaxy"},
{"source":"Bradley Cooper","target":"Guardians of the Galaxy"},
{"source":"Vin Diesel","target":"Guardians of the Galaxy"},
{"source":"Chris Pratt","target":"Guardians of the Galaxy"}]}
相反,我得到了相同的结果,只是在开头有一个额外的“{”节点“:”我想省略。
这就是我的意思
{"nodes": (<----- REMOVE/OMIT THIS LINE)
{"nodes":[
{"id":"James Gunn"},
{"id":"Zoe Saldana"},
{"id":"Bradley Cooper"},
{"id":"Vin Diesel"},
{"id":"Chris Pratt"},
{"id": "Guardians of the Galaxy",
"year":2014.0,
"director":"James Gunn",
"rating":8.1,
"runtime":121.0,
"description":"<Long desc>",
"label":"Movie",
"actors":["Chris Pratt","Vin Diesel","Bradley Cooper","Zoe Saldana"],
"revenue":333.13,
"genres":["Action","Adventure","Sci-Fi"],
"name":"Guardians of the Galaxy",
"rank":1.0,
"votes":757074.0,
"metascore":76.0}],
"links":[
{"source":"Zoe Saldana","target":"Guardians of the Galaxy"},
{"source":"Bradley Cooper","target":"Guardians of the Galaxy"},
{"source":"Vin Diesel","target":"Guardians of the Galaxy"},
{"source":"Chris Pratt","target":"Guardians of the Galaxy"}
]
}
} <-----(ALSO THIS LINE THAT CLOSES IT)
这是我当前的查询
`CALL apoc.export.json.query("MATCH (m:Movie)
WHERE m.name = 'Guardians of the Galaxy'
CALL apoc.path.subgraphAll(m, {maxLevel:1}) YIELD nodes, relationships
WITH [node in nodes | node {.*, id:node.name, label:labels(node)[0]}] as nodes,
[rel in relationships | rel {.*, source:startNode(rel).name, target:endNode(rel).name}] as rels
WITH {nodes:nodes, links:rels} as nodes
RETURN nodes"
, "file://./limit.json", {})`
我的问题是如何编写一个用户函数来允许我将字符串切片以按照我喜欢的方式进行格式化?
我假设它类似于 RETURN Slicing(nodes)
但据我所知,用户函数仅在 Java 中允许并且我在 React 中使用 JavaScript.
与其撰写新的 json 文档,不如尝试直接返回节点和链接,如
而不是,
...
WITH {nodes:nodes, links:rels} as nodes
RETURN nodes
...
尝试
...
RETURN nodes, rels as links
...
所以我正在对我的 Neo4j 数据库执行查询并返回预期的结果,尽管它的格式不同。我希望我的输出看起来像这样...
{"nodes":[
{"id":"James Gunn"},
{"id":"Zoe Saldana"},
{"id":"Bradley Cooper"},
{"id":"Vin Diesel"},
{"id":"Chris Pratt"},
{"id": "Guardians of the Galaxy",
"year":2014.0,
"director":"James Gunn",
"rating":8.1,
"runtime":121.0,
"description":"<Enter long desc here>",
"label":"Movie",
"actors":["Chris Pratt","Vin Diesel","Bradley Cooper","Zoe Saldana"],
"revenue":333.13,
"genres":["Action","Adventure","Sci-Fi"],
"name":"Guardians of the Galaxy",
"rank":1.0,
"votes":757074.0,
"metascore":76.0}],
"links":[
{"source":"Zoe Saldana","target":"Guardians of the Galaxy"},
{"source":"Bradley Cooper","target":"Guardians of the Galaxy"},
{"source":"Vin Diesel","target":"Guardians of the Galaxy"},
{"source":"Chris Pratt","target":"Guardians of the Galaxy"}]}
相反,我得到了相同的结果,只是在开头有一个额外的“{”节点“:”我想省略。 这就是我的意思
{"nodes": (<----- REMOVE/OMIT THIS LINE)
{"nodes":[
{"id":"James Gunn"},
{"id":"Zoe Saldana"},
{"id":"Bradley Cooper"},
{"id":"Vin Diesel"},
{"id":"Chris Pratt"},
{"id": "Guardians of the Galaxy",
"year":2014.0,
"director":"James Gunn",
"rating":8.1,
"runtime":121.0,
"description":"<Long desc>",
"label":"Movie",
"actors":["Chris Pratt","Vin Diesel","Bradley Cooper","Zoe Saldana"],
"revenue":333.13,
"genres":["Action","Adventure","Sci-Fi"],
"name":"Guardians of the Galaxy",
"rank":1.0,
"votes":757074.0,
"metascore":76.0}],
"links":[
{"source":"Zoe Saldana","target":"Guardians of the Galaxy"},
{"source":"Bradley Cooper","target":"Guardians of the Galaxy"},
{"source":"Vin Diesel","target":"Guardians of the Galaxy"},
{"source":"Chris Pratt","target":"Guardians of the Galaxy"}
]
}
} <-----(ALSO THIS LINE THAT CLOSES IT)
这是我当前的查询
`CALL apoc.export.json.query("MATCH (m:Movie)
WHERE m.name = 'Guardians of the Galaxy'
CALL apoc.path.subgraphAll(m, {maxLevel:1}) YIELD nodes, relationships
WITH [node in nodes | node {.*, id:node.name, label:labels(node)[0]}] as nodes,
[rel in relationships | rel {.*, source:startNode(rel).name, target:endNode(rel).name}] as rels
WITH {nodes:nodes, links:rels} as nodes
RETURN nodes"
, "file://./limit.json", {})`
我的问题是如何编写一个用户函数来允许我将字符串切片以按照我喜欢的方式进行格式化?
我假设它类似于 RETURN Slicing(nodes)
但据我所知,用户函数仅在 Java 中允许并且我在 React 中使用 JavaScript.
与其撰写新的 json 文档,不如尝试直接返回节点和链接,如
而不是,
...
WITH {nodes:nodes, links:rels} as nodes
RETURN nodes
...
尝试
...
RETURN nodes, rels as links
...