From the MERGE documentation
MATCH (person:Person)
MERGE (city:City { name: person.bornIn })
MERGE (person)-[r:BORN_IN]->(city)
RETURN person.name, person.bornIn, city
The problem is, I want to create a Relationship and a Node, if the RELATIONSHIP does not exist, but in my graph all the nodes are identical so the second step would not create a new Node.
Since my graph is a tree I know that if the relationship i'm looking for does not exist, the node also does not exist.
Giving the nodes unique identifiers is not helpful as it would just be the path from the root node to the one i want to create. If I replace MERGE with CREATE it will create redundant nodes that are not connected to the tree. Since you cant use MERGE with WHERE, is there a way to do the equivalent of:
MERGE (nextpos:Position) WHERE NOT (nextpos)--()
Which would create a node if there are no nodes without connections, allowing me in the next step to create the needed relationship. Or should I just remove all the redundant nodes afterwards? That would seem very hacky and I am hoping for an elegant solution.
question from:https://stackoverflow.com/questions/65906624/neo4j-create-node-if-no-relationship-exists