Database Reference
In-Depth Information
Adding a Label to Nodes
In Py2neo, you can add one more labels to a node. As Listing 9-9 shows, the add_labels function takes one or more
labels as argument. You can return each of the labels on a node by calling its get_labels function. The value used for
the label should be any nonempty string or numeric value.
Caution
A label will not exist on the database server until it has been added to at least one node.
Listing 9-9. Retrieving a Node and Adding a Label to It
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 its node id
userNode = graph_db.node(1)
# add the label
userNode.add_labels("User")
Removing a Label
Removing a label uses similar syntax as adding a label to a node. After the given label has been removed from the
node (Listing 9-10), the return value is a list of labels still on the node.
Listing 9-10. Removing a Label from 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)
# remove the label
userNode.remove_labels("Developer")
 
Search WWH ::




Custom Search