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 relation formed when parallel request recieved by a Node js function

Hi Team,

I am writing a node js function which contains a cypher query to form a relation between two person node if they met each other. When they met decide by the exchange of Bluetooth packet.

Problem is when many Bluetooth packets received by server simultaneously, there are many MET relationship formed between two-person node.

2X_d_d098fb7d2e46b1cf9eea16c9da9a9e645c450a64.png

My query look like this in psudo form
Match Person A with id X
Match Person B with id y
Optinal Match A and B has any MET relation in A-> B or B<-A
Then if no relation create A -[r:Met]-> B
if relation exist increse the count of met ( r.count++)

In any given case, there should be only one MET relationship in either A->B or B<-A.

1 ACCEPTED SOLUTION

gspitzer
Node Link

I don't believe the problem is the parallel access because afaik all nodes relevant to a transaction are locked until it finishes. Can you post your actual Cypher Query? For example this one works for me

MATCH (a:Person {id:x})
MATCH (b:Person {id:y})
MERGE (a)-[r:MET]->(b)
ON MATCH
SET r.count = r.count+1
ON CREATE
SET r.count = 0

View solution in original post

2 REPLIES 2

gspitzer
Node Link

I don't believe the problem is the parallel access because afaik all nodes relevant to a transaction are locked until it finishes. Can you post your actual Cypher Query? For example this one works for me

MATCH (a:Person {id:x})
MATCH (b:Person {id:y})
MERGE (a)-[r:MET]->(b)
ON MATCH
SET r.count = r.count+1
ON CREATE
SET r.count = 0

Yes, you are right.

Initial I thought this is due to the parallel requests received by function, but the main issue was.

I had query
Merge(a)-[r:MET{timeStamp:datetime($timeStamp), count:0}]->(b)

So each request has a different different time stamp and thus it was forming multiple MET relations instead of one.

I replace the query which you have highlighted above and it worked.