Skip to content

Instantly share code, notes, and snippets.

@calvindavis
Created June 27, 2013 13:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvindavis/5876477 to your computer and use it in GitHub Desktop.
Save calvindavis/5876477 to your computer and use it in GitHub Desktop.
Cypher query for toggling a relationship between two nodes.
START calvin = node(1), sophie = node(2)
CREATE (calvin)-[:LIKES]->(sophie)
MATCH (calvin)-[r:LIKES]->(sophie), (calvin)-[:LIKES]->(sophie)
DELETE r
RETURN count(r) = 1 AS likes
@mbarouski
Copy link

mbarouski commented Jun 22, 2018

Version without START, because it's deprecated in cypher 3.2

MATCH (u:User { id: {0} }), (p:Post { id: {1} })
CREATE (u)-[:LIKES]->(p)
WITH u, p MATCH (u)-[r:LIKES]->(p), (u)-[:LIKES]->(p)
DELETE r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment