Skip to content

Commit 7cd46f1

Browse files
Apply suggestions from code review
Co-authored-by: Jessica Wright <[email protected]>
1 parent 9334f31 commit 7cd46f1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

modules/ROOT/pages/cypher/updating.adoc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ MATCH (ann:Person {name: 'Ann'})
216216
RETURN ann
217217
--
218218

219-
You see there are two Nodes containing the same information:
219+
You see there are two nodes containing the same information:
220220

221221
[role="queryresult",options="header,footer",cols="1*<m"]
222222
|===
@@ -236,7 +236,7 @@ MERGE (ann:Person {name: 'Ann'})
236236
RETURN ann
237237
--
238238

239-
Cypher returns the existing node normally:
239+
Cypher returns the existing node without creating a new one:
240240

241241
[role="queryresult",options="header,footer",cols="1*<m"]
242242
|===
@@ -247,16 +247,16 @@ Cypher returns the existing node normally:
247247
1+d|Rows: 1
248248
|===
249249

250-
Now, if you want to add a relationship between two existing nodes, you need to first `MATCH` them or you will create the same duplication.
251-
For example, if you write:
250+
If you want to add a relationship between two existing nodes, you need to first `MATCH` them or you will create the same duplication.
251+
If you use `CREATE` to link Ann and Mark:
252252

253253
[source,cypher]
254254
--
255-
CREATE (j:Person {name: 'Ann'})-[r:IS_FRIENDS_WITH]->(m:Person {name: 'Mark'})
256-
RETURN j, r, m
255+
CREATE (a:Person {name: 'Ann'})-[r:IS_FRIENDS_WITH]->(m:Person {name: 'Mark'})
256+
RETURN a, r, m
257257
--
258258

259-
You duplicate Ann's node and create a new Mark node that was removed in xref:cypher/updating.adoc#_delete_a_node_and_its_relationships[the previous step] and a new `IS_FRIENDS_WITH` relationship between them.
259+
The result is that you duplicate Ann's node and create a new Mark node (since it was removed in xref:cypher/updating.adoc#_delete_a_node_and_its_relationships[the previous step]) and add a new `IS_FRIENDS_WITH` relationship between them.
260260
If you use `MERGE` instead:
261261

262262
[source,cypher]
@@ -265,11 +265,12 @@ MERGE (j:Person {name: 'Ann'})-[r:IS_FRIENDS_WITH]->(m:Person {name: 'Mark'})
265265
RETURN j, r, m
266266
--
267267

268-
You see in the result that you "Created 2 nodes, created 1 relationship, set 2 properties, added 2 labels", so another duplication.
268+
The result is more duplication.
269+
`MERGE` tries to match the *entire* pattern, and if it doesn't exist, it is created.
269270
This happens because `MERGE` tries to find the information queried and, if it doesn't exist, it is then created.
270271

271-
Even though the graph already has Ann and Mark's nodes, the pattern `(Ann)-[:IS_FRIENDS_WITH]->(Mark)` doesn't exist, so all elements of it are created anew.
272-
Instead, you need to first `MATCH` the nodes and then create the relationship.
272+
Even though the graph already has Ann and Mark's nodes, the pattern `(Ann)-[:IS_FRIENDS_WITH]->(Mark)` doesn't exist, so all elements are created anew.
273+
To avoid the duplication, you need to first `MATCH` the nodes and then create the relationship.
273274

274275
Since Mark's node was removed in xref:cypher/updating.adoc#_delete_a_node_and_its_relationships[the previous step], you need to create it again either by using `CREATE`:
275276

@@ -307,7 +308,7 @@ In order to create the new relationship, you need to first `MATCH` Ann and Mark'
307308
----
308309
MATCH (a:Person {name: 'Ann'})
309310
MATCH (m:Person {name: 'Mark'})
310-
MERGE (j)-[r:IS_FRIENDS_WITH]->(m)
311+
MERGE (a)-[r:IS_FRIENDS_WITH]->(m)
311312
RETURN a, r, m
312313
----
313314

0 commit comments

Comments
 (0)