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.


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.

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)
SET r.count = r.count+1
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.