KusGrus
KusGrus

Reputation: 85

Neo4j check relationship Python

I have graph in Neo4j, and I want to set the relationship between 2 nodes. For two nodes, 2 arrows are created in different directions, can I somehow replace it with one bidirectional one? enter image description here

for node in nodes_of_mobile:
        if nodes_mobile[node]['social_contact'] != 0:
            for neighbor in nodes_mobile[node]["social_contact"]:
                command = "MATCH (a:Person),(b:Person) WHERE " \
                          f"a.id='{node}' AND " \
                          f"b.id='{neighbor}' " \
                          "CREATE (a)-[r:Network]->(b)"
                graph_Neo4j.run(command)

I use python to fill in the links. If you can't create bidirectional relationships, can you determine if there is a specific type of connection between nodes and not repeat them again?

Upvotes: 0

Views: 194

Answers (1)

hoyski
hoyski

Reputation: 344

Neo4j doesn't have a concept of a bi-directional (or directionless) relationship.

To handle creating a relationship only if it doesn't already exist, use the Neo4j MERGE command instead of CREATE.

Upvotes: 1

Related Questions