diff --git a/modules/ROOT/content-nav.adoc b/modules/ROOT/content-nav.adoc index 223b28d68..1f2ddf6d0 100644 --- a/modules/ROOT/content-nav.adoc +++ b/modules/ROOT/content-nav.adoc @@ -73,6 +73,7 @@ *** xref:expressions/predicates/string-operators.adoc[] *** xref:expressions/predicates/path-pattern-expressions.adoc[] *** xref:expressions/predicates/type-predicate-expressions.adoc[] +** xref:expressions/node-relationship-operators.adoc[] ** xref:expressions/mathematical-operators.adoc[] ** xref:expressions/string-operators.adoc[] ** xref:expressions/temporal-operators.adoc[] diff --git a/modules/ROOT/images/graph_element_operators.svg b/modules/ROOT/images/graph_element_operators.svg new file mode 100644 index 000000000..1617bf92f --- /dev/null +++ b/modules/ROOT/images/graph_element_operators.svg @@ -0,0 +1 @@ +WORKS_FORsince:2023WORKS_FORsince:2015PersonfirstName:'Cecil'middleName:'David'lastName:'Ericson'PersonfirstName:'Cecilia'lastName:'Farega'PersonfirstName:'Alice'middleName:'Catherine'lastName:'Baxter' \ No newline at end of file diff --git a/modules/ROOT/pages/expressions/index.adoc b/modules/ROOT/pages/expressions/index.adoc index 5a05fe28f..df1119866 100644 --- a/modules/ROOT/pages/expressions/index.adoc +++ b/modules/ROOT/pages/expressions/index.adoc @@ -1,4 +1,7 @@ = Expressions +:description: Information about the expressions available in Cypher. +:page-aliases: syntax/operators.adoc + A Cypher expression is any part of a query that evaluates to a value. For details and examples of specific expressions, see the following sections: @@ -11,10 +14,10 @@ For details and examples of specific expressions, see the following sections: ** xref:expressions/predicates/string-operators.adoc[]: `STARTS WITH`, `ENDS WITH`, `CONTAINS`, `IS NORMALIZED`, `IS NOT NORMALIZED`, `=~` ** xref:expressions/predicates/path-pattern-expressions.adoc[]: information about filtering queries with path pattern expressions. ** xref:expressions/predicates/type-predicate-expressions.adoc[]: information about how to verify the value type of a Cypher expression. +* xref:expressions/node-relationship-operators.adoc[]: information about how to access `NODE` and `RELATIONSHIP` property values with `.` and `[]`. * xref:expressions/mathematical-operators.adoc[]: `+`, `-`, `*`, `/`, `%`, `^`. * xref:expressions/string-operators.adoc[]: `+`, `||` * xref:expressions/temporal-operators.adoc[]: `+`, `-`, `*`, `/` * xref:expressions/list-expressions.adoc[]: information about list concatenation operators (`||`, `+`), list element access, list slicing, and list as well as pattern comprehensions. * xref:expressions/map-expressions.adoc[]: information about map operators (`.`, `[]`) and map projection. * xref:expressions/conditional-expressions.adoc[] - diff --git a/modules/ROOT/pages/expressions/node-relationship-operators.adoc b/modules/ROOT/pages/expressions/node-relationship-operators.adoc new file mode 100644 index 000000000..65dc5a1bc --- /dev/null +++ b/modules/ROOT/pages/expressions/node-relationship-operators.adoc @@ -0,0 +1,183 @@ += Node and relationship operators +:description: Information about Cypher's node and relationship operators, which enable the querying and manipulation of nodes and relationships. + +Node and relationship operators allow you to manipulate and query `NODE` and `RELATIONSHIP` property values. +Cypher contains the following node and relationship operators: + +* Static property access: dot operator (`.`) +* Dynamic property access: subscript operator (`[]`) + +For functions that return metadata about `NODE` and `RELATIONSHIP` values, see: + +* xref:functions/scalar.adoc#functions-elementid[`elementId()`] +* xref:functions/scalar.adoc#functions-endnode[`endNode()`] +* xref:functions/scalar.adoc#functions-id[`id()`] +* xref:functions/list.adoc#functions-keys[`keys()`] +* xref:functions/list.adoc#functions-labels[`labels()`] +* xref:functions/scalar.adoc#functions-properties[`properties()`] +* xref:functions/scalar.adoc#functions-startnode[`startNode()`] +* xref:functions/scalar.adoc#functions-type[`type()`] + + +[[example-graph]] +== Example graph + +The following graph is used for the examples below: + +image::graph_element_operators.svg[width="600",role="middle"] + +To recreate the graph, run the following query against an empty Neo4j database: + +[source, cypher, role=test-setup] +---- +CREATE (alice:Person {firstName:'Alice', middleName: 'Catherine', lastName: 'Baxter'}), + (cecil:Person {firstName: 'Cecil', middleName: 'David', lastName: 'Ericson'}), + (cecilia:Person {firstName: 'Cecilia', lastName: 'Farega'}), + (cecil)-[:WORKS_FOR {since: 2023}]->(alice), + (cecilia)-[:WORKS_FOR {since: 2015}]->(alice) +---- + +[[static-property-access]] +== Static property access + +Property values can be accessed statically by specifying a property name after the `.` operator. + +.Access node properties statically +[source, cypher] +---- +MATCH (p:Person) +RETURN p.firstName AS name +---- + +.Result +[role="queryresult",options="header,footer",cols="1* 6 -RETURN DISTINCT restaurant.name ----- - -.Result -[role="queryresult",options="header,footer",cols="1* Filter on dynamic properties]. - -[NOTE] -==== -The behavior of the `[]` operator with respect to `null` is detailed xref::values-and-types/working-with-null.adoc#cypher-null-bracket-operator[here]. -==== - - -[[syntax-property-replacement-operator]] -=== Replacing all properties of a node or relationship using the `=` operator - -.Query -[source, cypher] ----- -CREATE (a:Person {name: 'Sofia', age: 20}) -WITH a -MATCH (p:Person {name: 'Sofia'}) -SET p = {name: 'Ellen', livesIn: 'London'} -RETURN p.name, p.age, p.livesIn ----- - -All the existing properties on the node are replaced by those provided in the map; i.e. the `name` property is updated from `Sofia` to `Ellen`, the `age` property is deleted, and the `livesIn` property is added. - -.Result -[role="queryresult",options="header,footer",cols="3*+ | +"London"+ - -3+d|Rows: 1 -|=== - -See xref::clauses/set.adoc#set-replace-properties-using-map[Replace all properties using a map and `=`] for more details on using the property replacement operator `=`. - - -[[syntax-property-mutation-operator]] -=== Mutating specific properties of a node or relationship using the `+=` operator - -.Query -[source, cypher] ----- -CREATE (a:Person {name: 'Sofia', age: 20}) -WITH a -MATCH (p:Person {name: 'Sofia'}) -SET p += {name: 'Ellen', livesIn: 'London'} -RETURN p.name, p.age, p.livesIn ----- - -The properties on the node are updated as follows by those provided in the map: the `name` property is updated from `Sofia` to `Ellen`, the `age` property is left untouched, and the `livesIn` property is added. - -.Result -[role="queryresult",options="header,footer",cols="3*