Creating Family Tree with Neo4J

前端 未结 4 1654
囚心锁ツ
囚心锁ツ 2020-12-29 00:50

I have a set of data for a family tree in Neo4J and am trying to build a Cypher query that produces a JSON data set similar to the following:

{Name:  \"Bob\"         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 01:23

    The only way I have found thus far to get the data I am looking for is to actually return the relationship information, like so:

    MATCH ft = (person {firstName: 'Bob'})<-[:PARENT]-(p:Person)
    RETURN EXTRACT(n in nodes(ft) | {firstName: n.firstName}) as parentage
    ORDER BY length(ft);
    

    Which will return a dataset I am then able to morph:

    ["Bob", "Roger"]
    ["Bob", "Susan"]
    ["Bob", "Roger", "Robert"]
    ["Bob", "Susan", "George"]
    ["Bob", "Roger", "Jessica"]
    ["Bob", "Susan", "Susan"]
    

提交回复
热议问题