Search code examples
neo4jcypherredisgraph

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


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?


Solution

  • 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)