Create Unique Node or Retrieve Unique Node

Description

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

Usage

1
getOrCreateNode(graph, .label, ...)

Arguments

graph

A graph object.

.label

A character string.

...

A named list. Node properties in the form key = value.

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.

Value

A node object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## 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)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.