1

How to create edges based on the equality check on vertex attributes in Cypher?

For example: lets say I have one object like this

Employees {name: "abc, country: "NZ"}

and lets say I have the following objects

Manager { name: "abc", depatment: "product"}

Manager {name: "abc", depatment: "sales"}

Manager {name: "abc", depatment: "marketing"}

Now I want to create all the edges where Employees.name = Manager.name

How do I write the Cypher query to create all 4 vertices and 3 edges?

user1870400
  • 6,028
  • 13
  • 54
  • 115

1 Answers1

2

Find the pairs first with MATCH clause and then CREATE a relationship between them.

MATCH (e:Employees),(m:Manager)
WHERE e.name=m.name
WITH e,m
CREATE (m)-[:REL_NAME]->(e)
Rajendra Kadam
  • 4,004
  • 1
  • 10
  • 24
  • Thanks. Another related question from this what if I have country list so say Country{name: NZ} and i want to create all the edges where e.name =m.name and e.county = country.name? Can MATCH take more than two vertices ? – user1870400 Mar 26 '19 at 10:57
  • Yes, It can take more than two vertices – Rajendra Kadam Mar 26 '19 at 11:01