Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@maximka777

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.