Neo4j可以返回其他属性地图

时间:2013-07-10 22:27:24

标签: neo4j

我正在手动使用cypher rest api。

我想以易于解析的方式返回数据。

以下是我正在处理的具有相同关系的一些数据的示例:

(me:Person:Normal),
(dad:Person:Geezer),
(brother:Person:Punk),
(niece:Person:Tolerable),
(daughter:Person:Awesome),
(candy:Rule),
(tv:Rule),
(dad)-[:HAS_CHILD {Num:1}]->(brother),
(dad)-[:HAS_CHILD {Num:2}]->(me),
(me)-[:HAS_CHILD {Num:1}]->(daughter),
(brother)-[:HAS_CHILD {Num:1}]->(niece),
(me)-[:ALLOWS]->(candy),
(me)-[:ALLOWS]->(tv)

我希望获得所有HAS_CHILD关系,如果这些子节点中的任何一个具有:ALLOWS关系,我也想要那些关键字。

所以,如果我做某事......

START n=node({idofdad}) MATCH n-[r?:HAS_CHILD]->h-[?:ALLOWS]->allowed
    WITH n, r, h, collect(ID(allowed)) as allowedIds
    WITH n, r, 
        CASE 
            WHEN h IS NOT NULL THEN [ID(h), LABELS(h), r.Num?, allowedIds] 
            ELSE NULL     
        END as has
RETURN
    LABELS(n) as labels,
    ID(n) as id,
    n as node,
    COLLECT(has) as children;

:HAS_CHILD可能不存在,所以我必须做这个奇怪的事情。

返回的数据是'ok'但是我拥有的JSON映射器(Newtonsoft)不容易将数组映射到对象(这意味着我知道数组索引[0]是(的ID)儿童)收藏品。

以上结果如下:     {       “columns”:[“labels”,“id”,“node”,“children”],       “数据”:[         [“人”,“Geezer”],         6,         {},         [          [7,[“人”,“正常”],2,[2,1]],          [5,[“人物”,“朋克”],1,[]]         ]       ]     }

由于这是一个更多/更少的文档,并且更容易映射'儿童'列我想得到这样的东西:

{
  "columns": ["labels", "id", "node", "children"], 
  "data": [
    ["Person", "Geezer"],
    6,
    {},
    [
     [
       "id": 7, 
       "labels": ["Person", "Normal"], 
       "ChildNumber": 2, 
       "AllowedIds": [2, 1]
     },
     {
       "id": 5, 
       "labels": ["Person", "Punk"], 
       "ChildNumber": 1, 
       "AllowedIds": []
     }
    ]
  ] 
}

我希望查询看起来像:

START n=node({idofdad}) MATCH n-[r?:HAS_CHILD]->h-[?:ALLOWS]->allowed
    WITH n, r, h, collect(ID(allowed)) as allowedIds
    WITH n, r, 
        CASE 
            WHEN h IS NOT NULL THEN 
               { id: ID(h), labels: LABELS(h), ChildNumber: r.Num?, AllowedIds: allowedIds }
            ELSE NULL     
        END as has
RETURN
    LABELS(n) as labels,
    ID(n) as id,
    n as node,
    COLLECT(has) as children;

这甚至是远程可能吗?

0 个答案:

没有答案