我正在尝试构建一个cypher查询,我打算将其用作对http请求的json响应。我想在json对象中有两个键:一个是string类型的键/属性,另一个是类型为array的键/属性,如下所示:
> {
> "id" : "9989898676876_all",
> "inventory" : [
> {
> "id" : "a_aaa",
> "isFavorite" : false
> }, {
> "id" : "b_bbb",
> "isFavorite" : false
> }, {
> "id" : "c_ccc",
> "isFavorite" : false
> }, {
> "id" : "d_ddd",
> "isFavorite" : false
> }
> ] }
我尝试使用此密码查询,但却出现错误:
MATCH n
WHERE n.id='9989898676876'
RETURN n.id + '_all' AS `id`
UNION
MATCH n-[inventory:ALL_]->leaf
WHERE n.id='9989898676876'
RETURN (leaf.id AS `id`, inventory.isFavorite AS `isFavorite`) AS `inventory`
有人可以提供一个cypher响应的小提琴示例,它将字符串的键/属性与数组的键/属性连接起来吗?
答案 0 :(得分:2)
通过升序leaf.id
订购广告资源,您可以获得结果:
MATCH n-[inventory:ALL_]->leaf
WHERE n.id='9989898676876'
WITH *
ORDER BY leaf.id
RETURN (n.id + '_all') AS id, COLLECT({ id: leaf.id, isFavorite: inventory.isFavorite }) AS inventory;