返回JSON格式的Neo4J响应

时间:2019-05-14 20:59:18

标签: graph neo4j cypher

我在Graph Databases世界中还很陌生,我正在尝试从Neo4J接收JSON格式的响应。我有下面的关系。 我预期的响应将是这样:

[
  {
    "id": "3cabc43c-59b6-47aa-b72f-3f1462c7ccfa",
    "name": "DependencyNetwork",
    "tasks": [
      {
        "id": "1e3217da-0df4-4162-80cd-3205b5740cc7",
        "name": "First",
        "department": "department",
        "earliestStart": 2,
        "duration": 5,
        "latestEnd": 4,
        "dependsOn": [
          {
            "id": "666752dd-6a73-44d8-a899-9c4151bbf9b5",
            "name": "Second"
          },
          {
            "id": "666752dd-6a73-44d8-a899-9c4151bbf9b5",
            "name": "Second"
          }
        ]
      },
      {
        "id": "666752dd-6a73-44d8-a899-9c4151bbf9b5",
        "name": "Second",
        "department": "department",
        "earliestStart": 2,
        "duration": 5,
        "latestEnd": 4,
        "dependsOn": [
          {
            "id": "1e3217da-0df4-4162-80cd-3205b5740cc7",
            "name": "First"
          }
        ]
      }
    ]
  }
]

现在我实现了下面的查询,这不是我想要做的:

MATCH (task:Task)-[r:BELONGS_TO]->(dn:DependencyNetwork)
         WITH task as task, dn as dn
         OPTIONAL  MATCH (task:Task)-[r:PRECEDES]->(dep:Task)
         WITH dn as dn, task as task, dep as dep
         RETURN dn.dId as dId, dn.name as dnName, 
         task.tId as tId, task.name as taskName, task.duration as taskDuration, task.latestEnd as taskLatestEnd,
         task.department as taskDepartment, task.earliestStart as taskEarliestStart,
         dep.tId as depId, dep.name as depName

enter image description here

0 个答案:

没有答案