Cypher结果返回某种结构

时间:2015-10-19 21:23:45

标签: neo4j

我正在尝试返回某个结构。 这是我的疑问:

MATCH (tracker:tracker { active: true }) OPTIONAL MATCH (tracker { active: true })--(timer:timer) RETURN { tracker:tracker, timers:COLLECT(timer) } as trackers

这是我到目前为止所回归的内容:

{
  "results": [{
    "columns": ["trackers"],
    "data": [{
      "row": [{
        "tracker": {
          "title": "a",
          "id": "04e3fddc-5aef-4c3a-9aeb-62a9fb15bd75",
          "active": true
        },
        "timers": []
      }]
    }]
  }],
  "errors": []
}

我希望定时器嵌套在跟踪器属性的“跟踪器”下,如下所示:

{
  "results": [{
    "columns": ["trackers"],
    "data": [{
      "row": [{
        "tracker": {
          "title": "a",
          "id": "04e3fddc-5aef-4c3a-9aeb-62a9fb15bd75",
          "active": true,
          "timers": []
      }]
    }]
  }],
  "errors": []
}

1 个答案:

答案 0 :(得分:1)

试试这个:

MATCH (tr:tracker {active: true}) 
OPTIONAL MATCH (tr)--(ti:timer) 
WITH { 
    title: tr.title, 
    id: tr.id,
    active: tr.active,
    timers: COLLECT(ti)
} as trackers
RETURN trackers
相关问题