Database Reference
In-Depth Information
and grace node). This is a very powerful approach for creating full paths of new nodes
and relationships with properties.
The Cypher create clause will create all elements in the matching pattern regardless
of whether or not they exist. If you ran the previous node snippet, which creates John's
friend Grace Spencer, twice, you'd end up with two Grace Spencer nodes and two
IS_FRIEND_OF relationships from John's node. This is probably not what you'd want.
Tocreateonlygraphentitiesthatdon'talreadyexist,youshouldusethe create unique
Cypher command, illustrated in the following snippet:
start john = node:users(name = "John Johnson")
create unique john
-[r:IS_FRIEND_OF]->
(grace {
name: 'Grace Spencer',
yearOfBirth: 1982, email: 'grace@mycompany.com'
})
return r, grace;
Theonlychangefromthepreviousexampleistheuseofthe create unique command.
Running this snippet multiple times will not multiply the number of entities—you will al-
ways have one Grace Spencer node and one IS_FRIEND_OF relationship between the
John and Grace nodes.
Now you know how to create new nodes, relationships, and properties, but how about de-
leting them? The next section will discuss deleting data from Neo4j using Cypher.
6.3.2. Deleting data
To delete a node, Cypher provides a delete command. Let's delete the user Grace you
just created:
Search WWH ::




Custom Search