【问题标题】:How to create a relation between two node having same node name in neo4j如何在neo4j中创建具有相同节点名称的两个节点之间的关系
【发布时间】:2017-04-28 13:11:09
【问题描述】:

我想在具有相同节点名的 abcd 节点和 vbnm 节点之间创建朋友关系 - 学生 neo4j graph database visualization

我执行以下查询,它没有显示任何错误,但此查询没有创建任何关系

match(Student:Stu),(Student:Stu)where Student.name="abcd" AND Student.name="vbnm" create(Student)-[fr:friends]->(Student)

【问题讨论】:

    标签: neo4j graph-databases


    【解决方案1】:

    你需要使用不同的变量名:

    match(Student1:Stu),(Student2:Stu)
    where Student1.name="abcd" AND 
                Student2.name="vbnm" 
    create(Student1)-[fr:friends]->(Student2)
    

    【讨论】:

      【解决方案2】:

      我认为您对语法有点困惑。让我给你一个MATCH查询语法的例子。

      MATCH (variable1:Label),(variable2:Label) where variable1.foo = variable2.foo
      

      您在查询中混合了标签和变量,每个实体都应该有自己的变量(变量 1 和变量 2),以便您可以与它们进行交互。 因此,在您的情况下,最佳查询类似于:

      MATCH (s1:Student),(s2:Student ) where s1.name="abcd" AND s2.name="vbnm" 
      CREATE (s1)-[:friends]->(s2)
      

      请注意,您无需将变量分配给 [:friends] 关系,因为您稍后不会在同一查询中与它进行交互。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多