-
Notifications
You must be signed in to change notification settings - Fork 41
Turning the page into a tutorial #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
AlexicaWright
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice rework!
| ==== | ||
| == Delete properties | ||
|
|
||
| Neo4j doesn't store null values, which means that if you set a property value as `null`, it will be automatically removed from your graph. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Neo4j doesn't store null values, which means that if you set a property value as `null`, it will be automatically removed from your graph. | |
| To remove a property, either use the `REMOVE` clause, or set its value to `null`. | |
| Neo4j doesn't store properties without values, so doing so removes the property from a node. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But even when you use REMOVE and then you MATCH it, you'll get null as value too. The sentence like that makes me understand that there's an option to literally remove the property, but it doesn't work like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is explained a few lines further down, that the result of both operations is "Set 1 property".
|
|
||
| == Conclusion | ||
|
|
||
| In this tutorial, you have seen how to update the information in your graph and avoid issues such as duplication or lack of information about when the changes were made. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| In this tutorial, you have seen how to update the information in your graph and avoid issues such as duplication or lack of information about when the changes were made. | |
| In this tutorial, you have seen how to update nodes, relationships, and properties. | |
| You have also seen how to delete data from the graph as well as how to avoid duplication when adding new data. |
Lacking information about when changes were made is not really an issue in most graphs, is it?
| |=== | ||
| | m | r | j | ||
|
|
||
| | (:Person {twitter: "@mark", name: "Mark"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, the twitter property was never added back after Mark's node was deleted.
| Earlier you learned how to represent nodes, relationships, labels, properties, and patterns in Cypher. | ||
| This section adds another level to your knowledge by introducing how to update and delete data with Cypher. | ||
| This tutorial shows how to update information in the graph by changing, removing, and adding nodes, relationships, and properties. | ||
| It also addresses how to avoid duplication and how to keep track of changes by adding new properties to the graph. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the main purpose of using merge action clauses is to track change, so maybe consider changing the end of this sentence? I left a comment in the relevant section as well.
Co-authored-by: Jessica Wright <[email protected]>
AlexicaWright
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great update! A few more comments. I recommend to run the example queries. You can run them in Desktop, easy peasy and you don't need to set up an Aura account. Let me know if you have any questions!
|
|
||
| Notice that here `MATCH` is used to find both Mark's node and Jennifer's node before we use `MERGE` to find or create the relationship between them. | ||
| Cypher can't find this pattern since Mark's node and all its relationships were deleted, and only their node was recreated. | ||
| Consequently, if you use `CREATE` instead of `MERGE`, the whole pattern is created (with both nodes and the relationship), which results in duplicate nodes for `Jennifer` and `Mark`, but a new relationship. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MERGE recreates the whole pattern, regardless of whether any of the nodes existed already or not. So if you run this using CREATE instead, you still get the same result: two Mark nodes and one Jennifer node.
The point to make here is that you need to MATCH the nodes first and then use MERGE to recreate the relationship.
Co-authored-by: Jessica Wright <[email protected]>
AlexicaWright
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not getting the same results when I run the queries. I can create duplicates and no errors are thrown.
| To start, let us look at an example of this by adding Mark back to our database using the query below. | ||
| You can use `MERGE` to ensure that Cypher checks the database for an existing node for Mark. | ||
| Since you removed Mark's node in the previous examples, Cypher will not find an existing match and will create the node new with the `name` property set to 'Mark'. | ||
| You won't get any results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you do, both queries yield the same results: Created 2 nodes, created 1 relationship, set 2 properties, added 2 labels. Duplicate Person nodes created and a new relationship between them added.
| ---- | ||
| -- | ||
| CREATE (mark:Person {name: 'Mark'}) | ||
| CREATE (jennifer:Person {name: 'Jennifer'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You used Ann in the two examples above?
Co-authored-by: Jessica Wright <[email protected]>
AlexicaWright
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting there! A few more comments, sorry ;)
|
|
||
| 1+d|Rows: 1 | ||
| |=== | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You had a great explanation of the difference between CREATE and MERGE before. I think you should keep that and place it here. It could be useful with a little summary of when to use which and why.
| If you run the same statement again, using `CREATE`, you will create another duplication. | ||
| But if you use `MERGE`, Cypher only finds the now existing node. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| If you run the same statement again, using `CREATE`, you will create another duplication. | |
| But if you use `MERGE`, Cypher only finds the now existing node. |
This has already been covered above.
| ==== | ||
|
|
||
| === Handling _MERGE_ criteria | ||
| `MATCH` finds both Mark and Ann's node before `MERGE` (finds or) creates the relationship between them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use CREATE here, it doesn't matter as long as there is no relationship already. What matters is that you MATCH Ann and Mark first and then use their variables in the MERGE clause. That's what avoids the duplication. I think we need to be clear about that.
Co-authored-by: Jessica Wright <[email protected]>
| -- | ||
|
|
||
| *Query result:* | ||
| Cypher returns the existing node without creating a new one: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there should be an example adding Jennifer back using merge to show what MERGE does? You had an explanation in there before, but if you don't want to put that back, I think we need to showcase that MERGE looks for the node/pattern and if it doesn't exist, creates it.
So using MERGE with Ann's node shows that there was a match so no creation of a new node, and using MERGE with Jennifer's node could show that when there is no match (since we deleted her in the previous example), a node is created. WDYT?
Co-authored-by: Jessica Wright <[email protected]>
AlexicaWright
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one last comment. Promise! It looks really good!
Co-authored-by: Jessica Wright <[email protected]>
AlexicaWright
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APPROVE!!!
|
Thanks for the documentation updates. The preview documentation has now been torn down - reopening this PR will republish it. |
* Turning the page into a tutorial * Apply suggestions from code review Co-authored-by: Jessica Wright <[email protected]> * updates after review * Apply suggestions from code review Co-authored-by: Jessica Wright <[email protected]> * updates after review and testing * Apply suggestions from code review Co-authored-by: Jessica Wright <[email protected]> * updates after review * Apply suggestions from code review Co-authored-by: Jessica Wright <[email protected]> * fixes after review * Apply suggestions from code review Co-authored-by: Jessica Wright <[email protected]> * update after review * Update modules/ROOT/pages/cypher/updating.adoc Co-authored-by: Jessica Wright <[email protected]> --------- Co-authored-by: Jessica Wright <[email protected]>
* Turning the page into a tutorial * Apply suggestions from code review * updates after review * Apply suggestions from code review * updates after review and testing * Apply suggestions from code review * updates after review * Apply suggestions from code review * fixes after review * Apply suggestions from code review * update after review * Update modules/ROOT/pages/cypher/updating.adoc --------- Co-authored-by: Jessica Wright <[email protected]>
No description provided.