I'd like to bundle a whole bunch of operations in as few requests as possible. The logic behind is should be the following:
- check if head with key=value exists, create if it doesn't
- check if tail with key=value exists, create if it doesn't
- create a unique relationship (all kinds of properties)
- set a bunch of properties for head & tail
I already stumbled upon create unique, but this seems to work for relationships only. How do I make sure that at least the head node exist so I can run a create unique statement on it?
What I'm doing now is firing multiple requests.The first one to find out if the node exists:
start x=node:index({key}={value}) return ID(x) as id
If that doesn't return an id, I fire another request to create the node and finally the final request to create the second node and relationships:
start n=node({id})
create unique n-[:POINTS_TO {label:{label}}]->(x {{key}:{value}})
return n,x
I'm wondering if there's a nicer way to bundle of all this...