Database Reference
In-Depth Information
Listing 9-5. Deleting a Node
from py2neo import neo4j, ogm, node, rel
# set connection information (defaults to: http://localhost:7474/db/data/)
graph_db = neo4j.GraphDatabaseService()
# find the user node by it's node id
userNode = graph_db.node(1)
# delete the node
userNode.delete()
# in some cases you might want to delete the node AND related notes and relationships
userNode.detele_related()
Creating a Relationship
Py2neo offers different methods to create relationships. The example in Listing 9-6 sets up the relationship using a
simple create method.
Both the start and end nodes of a relationship must already be established within the database before the
relationship can be saved.
Note
Listing 9-6. Relating Two Nodes
from py2neo import neo4j, ogm, node, rel
# set connection information (defaults to: http://localhost:7474/db/data/)
graph_db = neo4j.GraphDatabaseService()
# create two nodes
greg, = graph_db.create({"name": "Greg"})
brad, = graph_db.create({"name": "Brad"})
# create the relationship between the two nodes
graph_db.create(rel(greg, "FOLLOWS", brad))
 
 
Search WWH ::




Custom Search