I strongly recommend changing your DB schema. If all the nodes are having identical properties, I don't know how are you planning to perform MATCH
later on. All nodes might be identical to user but neo4j has a <id>
field, which is unique to each entity (node and relationship).
Anyways coming to the problem, As far as I understand you need to check if a particular node is already connected to another particular node. Since you didn't give the entities properties I assume some properties here.
DB elements
(:Position {position: prev_move})-[:Move {move: next_move}]->(:Position {position: next_move})
Cypher Query
MATCH (n: Position {position: prev_move})
OPTIONAL MATCH (n)-[rel:Move {move: next_move}]->(:Position {position: next_move))
CALL apoc.do.when(rel is NULL,
"CREATE (next: Position {position : next_move}) CREATE (n)-[:Move {move: next_move}]->(next) RETURN next",
"", {n:n})
YEILD value
RETURN n
EDIT
You might need a different MATCH
ing condition to get the exact node you are looking for. MATCH (n: Position {position: prev_move})
will yield in multiple nodes. Please fell free to update the matching condition, rest remains same.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…