Skip to content

Commit 480611b

Browse files
committed
update after review
1 parent 8581ef7 commit 480611b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

modules/ROOT/pages/cypher/updating.adoc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,34 @@ Cypher returns the existing node without creating a new one:
240240

241241
[role="queryresult",options="header,footer",cols="1*<m"]
242242
|===
243-
| j
243+
| ann
244244

245245
| (:Person {name: "Ann"})
246246

247247
1+d|Rows: 1
248248
|===
249249

250+
You can try using `MERGE` to see how it works when you don't have the data in the graph:
251+
252+
[source, cypher]
253+
--
254+
MERGE (j:Person {name: 'Jack'})
255+
RETURN j
256+
--
257+
258+
You get the message "Created 1 node, set 1 property, added 1 label" and the following result:
259+
260+
[role="queryresult",options="header,footer",cols="1*<m"]
261+
|===
262+
| j
263+
264+
| (:Person {name: "Jack"})
265+
266+
1+d|Rows: 1
267+
|===
268+
269+
This means Jack wasn't found in the graph, thus `MERGE` adds it.
270+
250271
If you want to add a relationship between two existing nodes, you need to first `MATCH` them or you will create the same duplication.
251272
If you use `CREATE` to link Ann and Mark:
252273

@@ -290,7 +311,6 @@ MERGE (a)-[r:IS_FRIENDS_WITH]->(m)
290311
RETURN a, r, m
291312
----
292313

293-
294314
image::ann-friends-mark.svg[Ann and Mark's nodes are connected through a is friends with relationship,width=400,role=popup]
295315

296316
== Conclusion

0 commit comments

Comments
 (0)