有没有更好的方法来RETURN关系._fromId AS relationship.source

时间:2017-01-24 14:26:40

标签: neo4j cypher

我正在尝试以特定格式返回JSON关系数组:

links: [
    {
        id: 3,
        source: 1,
        target: 2
    }
]

这是我的疑问:

MATCH ()-[link]->()
RETURN {id: ID(link), source: ID(startNode(link)), target: ID(endNode(link))} AS links

当然ID(startNode(link))不是最有效的方法吗?

鉴于RETURN {id: ID(link), source: link._fromId, target: link._toId} AS links返回null来源&目标,如何改进此查询?

1 个答案:

答案 0 :(得分:0)

您始终可以在开始和结束节点上包含变量,并返回这些变量的ID。我不能说哪个更有效率,你必须PROFILE两种方法来查看哪些数据库命中率更低。

    import time
    print ( "loading cakes.. please wait")
    time.sleep(3)
    print ("cakes now loaded - enjoy your program")
    time.sleep(1)

    print ( "Enter a People Name" )
    name = (input())

    print ( "Enter Years of a People, I'll tell you the Years in Doggo : ", end = "")
    ppl = float(input())

    doggo = ppl * 7


    print (name, "Is a People, with a People Years of", ppl, )
    print (name,"'s Age in People Years is", ppl, " and is equal to", doggo, "Doggo Years " )
    time.sleep(2)
    print("(・・;) you're so old") 

修改

尝试使用电影图表的两种方法都会显示相同的执行计划和数据库命中,因此请选择哪种方法在语法上更适合您。