cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Multiple queries with same MATCH statement

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.