Showing results for 
Search instead for 
Did you mean: 

Single queries vs Transactions

We need a simple way to refresh data in the graph, so - Delete existing data and create new data - and of course we want it to fully succeed or not succeed at all. (we are using nodejs)

Looking at the Transactions Documentation it says:

While it is not possible to run a Cypher query outside a transaction...

From this I understand that as an alternative to running several queries in a transaction like suggested here we can also "Concatenate" queries to 1 query and it will be run as a single query.

So we can connect 2 queries with the WITH keyword (without using the piped result)

So we will end up with something like

MATCH (delItem {id:"..."}) DETACH DELETE delItem
WITH delItem
UNWIND $param AS a MERGE (asset:foo {id:, accountId: a.accountId}) SET asset = a

$param is the name of the data object attached to the query.

So we attached a delete and an unwind clauses with a WITH clause.

Is this a good alternative to transactions? Is there a better way to do it?

Nodes 2022
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.