Alfred Zhong
Alfred Zhong

Reputation: 7091

How to use cypher to create relationship between two nodes given their attributes in Neo4j

I would like to do something like this

START n=node(*), m=node(*)  where has(n.userid) and has(m.userid) and n.userid='0' and m.userid='3'  create (n)-[FRIENDSHIP {status:2}]->(m) ;

However, Neo4j doesn't like the where clause. What is the best way to do this?

Thanks a lot!

Upvotes: 3

Views: 4963

Answers (1)

Luanne
Luanne

Reputation: 19373

What error did you get indicating that Neo4j didn't like the where clause?

I ran

START n=node(*), m=node(*)  
where has(n.name) and has(m.name) and n.name='Neo'
create (n)-[:FRIENDSHIP {status:2}]->(m)

on console.neo4j.org and it ran fine. Note that you missed the : preceding the relation name. Was that the error it complained about?

What version are you using in case this still does not work?

Upvotes: 8

Related Questions