cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple queries with same MATCH statement

muzos07
Node

Hello,

I'm using driver for Neo4j database with this code:

As you can see, I create query and then I might or might not create other nodes BASED on some conditions and collections.
Problem is that every time I have to match that first node again and again.

Is there some way I can temporally store the first node into some variable, so I dont have to search for that?

1 ACCEPTED SOLUTION

Your first statement could do a return id(n) as id.

In your follow-up statements you'd use match (n) where id(n)=$i .... and pass in {id: <id from 1st query>} as a parameter. This does a simple lookup by id which is basically a seek operation - extremely fast.

Another idea would be to run all your stuff in one single statement, cypher has a foreach / unwind.

View solution in original post

1 REPLY 1

Your first statement could do a return id(n) as id.

In your follow-up statements you'd use match (n) where id(n)=$i .... and pass in {id: <id from 1st query>} as a parameter. This does a simple lookup by id which is basically a seek operation - extremely fast.

Another idea would be to run all your stuff in one single statement, cypher has a foreach / unwind.

Nodes 2022
Nodes
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.