1
votes

I have 2 types of node staff and client where staff has StaffList

{
  "name": "vipul",
  "cprNumber": 121
}
,{
  "name": "amit",
  "cprNumber": 123
}

ClientList

{
  "property1": "pptVal",
  "cprNumber": 121
}

now I want to create a relationship between these 2 nodes like in the first case the CPR number is matched so a relationship creates "BELONGS_TO" for vipul, but since no, any node exists for amit's cpr number so a new node needs to be created and a relationship to be created.

1
Are you try merge?stdob--
if match found then merge else create a new node and add the relationVipul Pandey
imgur.com/a/UPxLw Please look reference ImageVipul Pandey

1 Answers

1
votes

I think you can achieve your goal using MERGE:

// Match Vipul and Amit nodes
MATCH (a:Client)
// Match :ClientList node when it has cprNumber = a.cprNumber.
// When no node is matched, create it.
MERGE (b:ClientList {cprNumber : a.cprNumber})
// Create :BELONGS_TO relationship
CREATE (a)-[:BELONGS_TO]->(b)