简体   繁体   中英

Neo4j - Cypher read-write-return query

I'm fairly new to neo4j. I've played a little bit with cypher and REST API. I want to be able to create a leaf node along certain path, consider these nodes are some types of events. I wouldn't know during run time the id of the node this event will be attached to. I need to either do a look-up and then get the id of the node and then create my new node.

So during run time I was hoping I can do a MATCH using cypher to get the node to which I can attach the event and CREATE new node along with the relationship to the existing node returned by MATCH. So I came across the cypher cheat sheet which has a read-write-return query which I thought would be good fit. But there is nothing much mentioned about it in documentation or may be I'm not a super googler!!

Could someone please tell me if this(read-write-return) is the right/valid approach?

Many Thanks!

Yep. That's a good approach. That's one of the nice things about how CREATE works in Cypher. You can also optionally use create unique which creates the rel/node at the same time. Something like:

start n=node(1)
create unique n-[:event]->(event {prop:"val"})
return n, event;

Or without create unique :

start n=node(1)
create (event {prop:"val"}), n-[:event]->event
return n, event;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM