Skip to content

Commit cb82eb4

Browse files
all but map format
1 parent 159e6e3 commit cb82eb4

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

modules/ROOT/pages/expressions/map-expressions.adoc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
Map expressions allow you to manipulate and query xref:values-and-types/maps.adoc[`MAP`] values in Cypher.
66

7+
[NOTE]
8+
The xref:functions/list.adoc#functions-keys[`keys()`] function can be used to return a `LIST` of all the keys in a `MAP`.
9+
710
[[example-graph]]
811
== Example graph
912

1013
The following graph is used for the examples below:
1114

12-
image::values_and_types_maps_graph.svg[width="600",role="middle"]
15+
image::values_and_types_maps_graph.svg[width="700",role="middle"]
1316

1417
To recreate the graph, run the following query against an empty Neo4j database:
1518

@@ -328,23 +331,22 @@ RETURN map{a: map.a, valueSum: map.a + map.b + map.c} AS projectedMap
328331
1+d|Rows: 1
329332
|===
330333
331-
The below query finds the `Keanu Reeves` node and the movies he has acted in.
332-
It is an example of a map projection with a literal entry, which in turn also uses map projection inside the aggregating xref:functions/aggregating.adoc#functions-collect[collect()] function.
334+
This query uses a map projection with a literal entry, where the `size(movies)` expression calculates the total number of movies `Keanu Reeves` has acted in.
333335
334336
.Map projection with a literal entry
335337
[source, cypher, indent=0]
336338
----
337339
MATCH (keanu:Person {name: 'Keanu Reeves'})-[:ACTED_IN]->(movie:Movie)
338-
WITH keanu, collect(movie{.title, .released}) AS movies
339-
RETURN keanu{.name, movies: movies} AS keanuMovies
340+
WITH keanu, collect(movie) AS movies
341+
RETURN keanu {.name, totalMovies: size(movies)} AS keanuDetails
340342
----
341343
342344
.Result
343345
[role="queryresult",options="header,footer",cols="1*<m"]
344346
|===
345-
| keanuMovies
347+
| keanuDetails
346348
347-
| {name: "Keanu Reeves", movies: [{title: "The Matrix Revolutions", released: 2003}, {title: "The Matrix Reloaded", released: 2003}, {title: "The Matrix", released: 1999}, {title: "The Devils Advocate", released: 1997}, {title: "The Matrix Resurrections", released: 2021}]}
349+
| {name: "Keanu Reeves", totalMovies: 5}
348350
349351
1+d|Rows: 1
350352
|===
@@ -381,17 +383,17 @@ It uses the xref::functions/aggregating.adoc#functions-count[count()] function t
381383
[source, cypher]
382384
----
383385
MATCH (actor:Person)-[:ACTED_IN]->(movie:Movie)
384-
WITH actor, count(movie) AS numberOfMovies
385-
RETURN actor{numberOfMovies, .name} AS nameAndMovies
386+
WITH actor, count(movie) AS totalMovies
387+
RETURN actor{totalMovies, .name} AS nameAndMovies
386388
----
387389
388390
.Result
389391
[role="queryresult",options="header,footer",cols="1*<m"]
390392
|===
391393
| nameAndMovies
392394
393-
| {name: "Keanu Reeves", numberOfMovies: 5}
394-
| {name: "Carrie-Anne Moss", numberOfMovies: 4}
395+
| {name: "Keanu Reeves", totalMovies: 5}
396+
| {name: "Carrie-Anne Moss", totalMovies: 4}
395397
396398
1+d|Rows: 2
397399
|===

0 commit comments

Comments
 (0)