joseph_pindi
joseph_pindi

Reputation: 867

Neo4j relationships not appearing

I've installed Neo4j Community edition version 2 and am running into a little problem linking nodes. Given the following:

CREATE (Hucksted_Gerald:contributor {name:'Hucksted_Gerald', type:'Individual'})
CREATE (contributionID207:contribution {amount:200.00})
CREATE (L4N7G2:PostalCode {name:'L4N7G2'})
CREATE (C_Gold_Mitch:Candidate {name: 'Gold_Mitch'})

This works fine, I've just created four nodes. I would have thought that this would work. Instead it creates four new nodes with no properties, which the original four are still there with no relationships attached.

CREATE (L4N7G2)<-[:LIVES]-(Hucksted_Gerald)-[:CONTRIBUTED]->(contributionID207)-[:RECEIVED]->(C_Gold_Mitch)

Does anyone have any ideas? I tried splitting the relationships up e.g. just using the following:

CREATE (L4N7G2)<-[:LIVES]-(Hucksted_Gerald)

...and no dice. It creates yet again two nodes with no properties with a relationship between them. Help?

Upvotes: 0

Views: 114

Answers (1)

Nicholas
Nicholas

Reputation: 7501

I believe you have to do these in 1 step:

CREATE (Hucksted_Gerald:contributor {name:'Hucksted_Gerald', type:'Individual'})
CREATE (contributionID207:contribution {amount:200.00})
CREATE (L4N7G2:PostalCode {name:'L4N7G2'})
CREATE (C_Gold_Mitch:Candidate {name: 'Gold_Mitch'})
CREATE (L4N7G2)<-[:LIVES]-(Hucksted_Gerald)-[:CONTRIBUTED]->(contributionID207)-[:RECEIVED]->(C_Gold_Mitch)

In your original request, you are creating those nodes. In the second request, you are referencing nodes you created previously, but the console has no memory, so it's going to assume you want to create those nodes with no properties.

Neo4j doesn't have the concept of "named" nodes, just labels and properties, so what you do in one query in terms of variable naming doesn't carry over to another query.

You can make your second query work if you do a MATCH than a create.

//EDIT:

You can replace the CREATE in your first query with MATCH, and append your second query to do this as well.

MATCH (Hucksted_Gerald:contributor {name:'Hucksted_Gerald', type:'Individual'})
MATCH (contributionID207:contribution {amount:200.00})
MATCH (L4N7G2:PostalCode {name:'L4N7G2'})
MATCH (C_Gold_Mitch:Candidate {name: 'Gold_Mitch'})
CREATE (L4N7G2)<-[:LIVES]-(Hucksted_Gerald)-[:CONTRIBUTED]->(contributionID207)-[:RECEIVED]->(C_Gold_Mitch)

Upvotes: 1

Related Questions