Database Reference
In-Depth Information
Adding a Label to Nodes
In Neography, you can add one more labels to a node. As Listing 10-11 shows, the
addLabels
function takes one or
more labels as argument. You can return each of the labels on a node by calling its
getLabels
function. The value used
for the label should be any nonempty string or numeric value.
Listing 10-11.
Creating a Label and Adding It to a Node
require 'neography'
neo = Neography::Rest.new({ :protocol => 'http://', :server => 'localhost', :port => 7474,
:directory => '/db/data'})
greg = neo.get_node(1)
# add single label
neo.add_label(greg, "User")
# add multiple labels
neo.add_label(greg, ["User ", "Developer"])
■
Caution
A label will not exist on the database server until it has been added to at least one node.
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 10-12), the return value is a list of labels still on the node.
Listing 10-12.
Removing a Label from a Node
require 'neography'
neo = Neography::Rest.new({ :protocol => 'http://', :server => 'localhost', :port => 7474,
:directory => '/db/data'})
greg = neo.get_node(1)
# delete single label
neo.delete_label greg, "Developer"
Querying with a Label
To get nodes that use a specific label, use the function called
getNodes.
This function returns value is a result Row
object, which can be iterated over like an array (Listing 10-13).