Hello,
I'm trying to create a database with nodes (A)-(B)-(C) and later add node
(D) and connect it to (C). Unfortunately, on the second run my code
creates creates (D), a new node ( ) that I wasn't expecting, and connects
them. The first time my code is run it clears out the database and create
nodes A,B, and C, and their relationships. The second time it is run it
creates the new ( ) node and (D), and a relationship between them. I was
expecting a result of (A)-(B)-(C)-(D), but I'm getting (A)-(B)-(C) and (
)-(D).
Any help would be greatly appreciated! Thank you!
from py2neo import Graph, Node, Relationship
session = Graph("bolt://localhost")
neo4j = session.begin()
# Check for Node C
existing_node = neo4j.run("MATCH (n) WHERE n.name=\"NODE_C\" RETURN n")
if existing_node:
print('Node Exists')
# Create Node D
neo_data_d = Node("NODE_D", name="NODE_D")
neo4j.create(neo_data_d)
# Create Relationship
rel = Relationship(existing_node, "REL", neo_data_d)
neo4j.create(rel)
neo4j.commit()
else:
print('Node Does Not Exist')
# Wipe Database
session.delete_all()
# Create Nodes A,B,C
neo_data_a = Node("NODE_A", name="NODE_A")
neo4j.create(neo_data_a)
neo_data_b = Node("NODE_B", name="NODE_B")
neo4j.create(neo_data_b)
neo_data_c = Node("NODE_C", name="NODE_C")
neo4j.create(neo_data_c)
# Create Relationships A-B-C
rel = Relationship(neo_data_a, "REL", neo_data_b)
neo4j.create(rel)
rel = Relationship(neo_data_b, "REL", neo_data_c)
neo4j.create(rel)
neo4j.commit()
--
You received this message because you are subscribed to the Google Groups
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.