RNeo4j (version 1.6.4)

getOrCreateNode: Create Unique Node or Retrieve Unique Node

Description

Create a unique node or retrieve it if it already exists.

Usage

getOrCreateNode(graph, .label, ...)

Arguments

graph
A graph object.
.label
A character string.
...
A named list. Node properties in the form key = value.

Value

A node object.

Details

A uniqueness constraint must exist for the given node label and first key = value pair listed in .... Use addConstraint to add a uniqueness constraint.

Examples

Run this code
## Not run: 
# graph = startGraph("http://localhost:7474/db/data/")
# clear(graph)
# 
# createNode(graph, "Person", name = "Alice", age = 24)
# createNode(graph, "Person", name = "Bob", age = 21)
# 
# addConstraint(graph, "Person", "name")
# 
# # Alice is retrieved from the graph; a new node is not created.
# alice = getOrCreateNode(graph, "Person", name = "Alice")
# 
# # Additional properties listed after the unique key = value
# # pair are ignored if the node is retrieved instead of
# # created.
# bob = getOrCreateNode(graph, "Person", name = "Bob", age = 22)
# 
# # Node doesn't exist, so it is created.
# charles = getOrCreateNode(graph, "Person", name = "Charles")
# 
# # There are now three nodes in the graph.
# length(getLabeledNodes(graph, "Person"))
# ## End(Not run)

Run the code above in your browser using DataLab