File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
modules/ROOT/pages/cypher Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff 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
2472471+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+
250271If you want to add a relationship between two existing nodes, you need to first `MATCH` them or you will create the same duplication.
251272If you use `CREATE` to link Ann and Mark:
252273
@@ -290,7 +311,6 @@ MERGE (a)-[r:IS_FRIENDS_WITH]->(m)
290311RETURN a, r, m
291312----
292313
293-
294314image::ann-friends-mark.svg[Ann and Mark's nodes are connected through a is friends with relationship,width=400,role=popup]
295315
296316== Conclusion
You can’t perform that action at this time.
0 commit comments