I created two labels A and B with a relationship CONNECT. I need to create multiple nodes of of each label A and B and a relationship between them. i.e, for each node A and B, I need to create a relationship. e.g.: a1:A -[:CONNECT]-> b1:B, a2:A -[:CONNECT]-> b2:B,a3:A -[:CONNECT]-> b3:B, ... an:A -[:CONNECT]-> bn:B
Is there a way to create the relationship automatically? When I create nodes, can the db automatically create a relationship between the nodes of different existing labels? Please help.
I used the APOC procedure to create multiple relationships between nodes manually on a property - for 100 nodes of labels LABEL1 and LABEL2, on a property value, I can create a relationships manually with a single Cypher query using below proc:
MATCH (ref1:LABEL1), (ref2:LABEL2)
WHERE ref1.property = ref2.property
CALL apoc.create.relationship(ref1, ‘RELATIONSHIP_NAME', {}, ref2) YIELD rel
RETURN rel
But I want to know if a way exists, where a relationship between two labels A and B already exists; and whenever a new node of label A and B are created, a relationship automatically creates without running a cypher query.