'how to ensure atomicity in neo4j cypher writes:

I have never used the transaction lock features in neo4j cypher before so I not sure how to do this. I have a series of writes that I need all to complete or none complete:

CREATE (e:Elections) SET e +=$electionObj,
                             e.election_id=apoc.create.uuid(),e.createdAt=date()

                            WITH e, $nominate_authorizers AS na
                            UNWIND na AS n_auth 
                            MATCH (nm:Member {member_id: n_auth.member_id})
                            CREATE (nm)-[nr:NOMINATE_AUTHORIZER]->(e)

                            WITH e, nm, $certify_authorizers AS ca
                            UNWIND ca AS c_auth 
                            MATCH (cm:Member {member_id: c_auth.member_id})
                            CREATE (cm)-[cr:CERTIFY_AUTHORIZER]->(e)

                            WITH e, nm,cm, $tally_authorizers AS ta
                            UNWIND ta AS t_auth 
                            MATCH (tm:Member {member_id: t_auth.member_id})
                            CREATE (tm)-[tr:TALLY_AUTHORIZER]->(e)

                            WITH e, nm,cm, tm, $audit_authorizers AS aa
                            UNWIND aa AS a_auth 
                            MATCH (am:Member {member_id: a_auth.member_id})
                            CREATE (am)-[ar:AUDIT_AUTHORIZER]->(e)

                            WITH e, nm,cm, tm, am, $races AS races
                            UNWIND races AS race 
                            CREATE (r:Race) 
                            SET r.name= race, 
                            r.race_id=apoc.create.uuid()
                            CREATE (r)-[rr:OF_ELECTION]->(e) 
                            
                            RETURN {election: e}

The problem is ...if there's an error that causes one of these MATCH's to return 0 row the query moves right along and creates the nodes it found. What is the most efficient of achieving atomicity here. I have looked at the apoc library but not sure about it....any suggestion would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source