Cypher relationships disconnected from nodes (pointing to nothing). Variable names wrong?

我与影子孤独终老i 提交于 2019-12-12 06:05:53

问题


I'm expecting this script

// $ cd ~/Documents/neo4j-community-2.2.5/bin
// $ ./neo4j-shell -file ~/Documents/neo4j_input/neo4j_queries.txt    

//Purge
MATCH ()-[r]-() DELETE r;
MATCH (n) DELETE n;    

CREATE (p1:Person { first_name: "Apple", age: 9 });
CREATE (p2:Person { first_name: "Bear", age: 44 });    

CREATE (p2)-[x:ISPARENTOF]->(p1);
CREATE (p1)-[x2:ISCHILDOF]->(p2);

to look like this, with the relationships pointing from each person to the other:

     -ISCHILDOF->
(p1)             (p2)
    <-ISPARENTOF-

But instead the relationships are pointing to thin air. What am I missing?


回答1:


Identifiers are only relevant within the scope of the query. You're executing separate queries.

CREATE (p1:Person { first_name: "Apple", age: 9 });
CREATE (p2:Person { first_name: "Bear", age: 44 });    

CREATE (p2)-[x:ISPARENTOF]->(p1);
CREATE (p1)-[x2:ISCHILDOF]->(p2);

In the 3rd and 4th queries, p1 and p2 are not bound to anything. You're creating nodes with no labels and no properties. You just need to remove the semicolons so that it's one query.

CREATE (p1:Person { first_name: "Apple", age: 9 })
CREATE (p2:Person { first_name: "Bear", age: 44 })

CREATE (p2)-[x:ISPARENTOF]->(p1)
CREATE (p1)-[x2:ISCHILDOF]->(p2);

In this query, p1 and p2 are bound when they're created at lines 1 and 2 respectively and used again at lines 4 and 5.



来源:https://stackoverflow.com/questions/34073959/cypher-relationships-disconnected-from-nodes-pointing-to-nothing-variable-nam

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!