đŸ•·ïž Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 27 (from laksa093)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

â„č Skipped - page is already crawled

📄
INDEXABLE
✅
CRAWLED
12 days ago
đŸ€–
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.4 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html
Last Crawled2026-03-30 23:01:07 (12 days ago)
First Indexed2016-04-15 16:24:08 (9 years ago)
HTTP Status Code200
Meta TitleNeo4j: COLLECTing multiple values
Meta DescriptionOne of my favourite functions in Neo4j’s cypher query language is COLLECT which allows us to group items into an array for later consumption. However,
Meta Canonicalnull
Boilerpipe Text
One of my favourite functions in Neo4j’s cypher query language is COLLECT which allows us to group items into an array for later consumption. However, I’ve noticed that people sometimes have trouble working out how to collect multiple items with COLLECT and struggle to find a way to do so. Consider the following data set: create (p:Person {name: "Mark"}) create (e1:Event {name: "Event1", timestamp: 1234}) create (e2:Event {name: "Event2", timestamp: 4567})   create (p)-[:EVENT]->(e1) create (p)-[:EVENT]->(e2) If we wanted to return each person along with a collection of the event names they’d participated in we could write the following: $ MATCH (p:Person)-[:EVENT]->(e) > RETURN p, COLLECT(e.name); +--------------------------------------------+ | p | COLLECT(e.name) | +--------------------------------------------+ | Node[0]{name:"Mark"} | ["Event1","Event2"] | +--------------------------------------------+ 1 row That works nicely, but what about if we want to collect the event name and the timestamp but don’t want to return the entire event node? An approach I’ve seen a few people try during workshops is the following: MATCH (p:Person)-[:EVENT]->(e) RETURN p, COLLECT(e.name, e.timestamp) Unfortunately this doesn’t compile: SyntaxException: Too many parameters for function 'collect' (line 2, column 11) "RETURN p, COLLECT(e.name, e.timestamp)" ^ As the error message suggests, the COLLECT function only takes one argument so we need to find another way to solve our problem. One way is to put the two values into a literal array which will result in an array of arrays as our return result: $ MATCH (p:Person)-[:EVENT]->(e) > RETURN p, COLLECT([e.name, e.timestamp]); +----------------------------------------------------------+ | p | COLLECT([e.name, e.timestamp]) | +----------------------------------------------------------+ | Node[0]{name:"Mark"} | [["Event1",1234],["Event2",4567]] | +----------------------------------------------------------+ 1 row The annoying thing about this approach is that as you add more items you’ll forget in which position you’ve put each bit of data so I think a preferable approach is to collect a map of items instead: $ MATCH (p:Person)-[:EVENT]->(e) > RETURN p, COLLECT({eventName: e.name, eventTimestamp: e.timestamp}); +--------------------------------------------------------------------------------------------------------------------------+ | p | COLLECT({eventName: e.name, eventTimestamp: e.timestamp}) | +--------------------------------------------------------------------------------------------------------------------------+ | Node[0]{name:"Mark"} | [{eventName -> "Event1", eventTimestamp -> 1234},{eventName -> "Event2", eventTimestamp -> 4567}] | +--------------------------------------------------------------------------------------------------------------------------+ 1 row During the Clojure Neo4j Hackathon that we ran earlier this week this proved to be a particularly pleasing approach as we could easily destructure the collection of maps in our Clojure code.
Markdown
- [Knowledge Base](https://www.javacodegeeks.com/) - [Tutorials](https://www.javacodegeeks.com/tutorials) - [Java Tutorial](https://www.javacodegeeks.com/java-tutorial) - [Core Java Tutorials](https://www.javacodegeeks.com/core-java-tutorials) - [Java 8 Tutorials](https://www.javacodegeeks.com/java-8-tutorials) - [Java 9 Tutorials](https://www.javacodegeeks.com/java-9-tutorials) - [Java Concurrency Tutorials](https://www.javacodegeeks.com/java-concurrency-tutorials) - [Java NIO Tutorials](https://www.javacodegeeks.com/java-nio-tutorials) - [Java Logging Tutorials](https://www.javacodegeeks.com/java-logging-tutorials) - [Design Patterns Tutorials](https://www.javacodegeeks.com/design-patterns-java-tutorials) - [Exception Handling Tutorials](https://www.javacodegeeks.com/java-exception-handling-tutorials) - [JUnit Tutorials](https://www.javacodegeeks.com/junit-tutorials) - [XPath Tutorials](https://www.javacodegeeks.com/xpath-tutorials) - [Mockito Tutorials](https://www.javacodegeeks.com/mockito-tutorials) - [Enterprise Java Tutorials](https://www.javacodegeeks.com/enterprise-java-tutorials) - [Java Spring Tutorial](https://www.javacodegeeks.com/java-spring-tutorial) - [Spring Boot Tutorials](https://www.javacodegeeks.com/spring-boot-tutorials) - [Spring Data Tutorials](https://www.javacodegeeks.com/spring-data-tutorials) - [Spring Batch Tutorials](https://www.javacodegeeks.com/spring-batch-tutorials) - [Spring Integration Tutorials](https://www.javacodegeeks.com/spring-integration-tutorials) - [Spring MVC Tutorials](https://www.javacodegeeks.com/spring-mvc-tutorials) - [Spring Security Tutorials](https://www.javacodegeeks.com/spring-security-tutorials) - [JDBC Tutorials](https://www.javacodegeeks.com/jdbc-tutorials) - [Hibernate Tutorials](https://www.javacodegeeks.com/hibernate-tutorials) - [Selenium Tutorials](https://www.javacodegeeks.com/selenium-tutorials) - [Java Servlet Tutorials](https://www.javacodegeeks.com/java-servlet-tutorials) - [JPA Tutorials](https://www.javacodegeeks.com/jpa-tutorials) - [JSF Tutorials](https://www.javacodegeeks.com/jsf-tutorials) - [JSP Tutorials](https://www.javacodegeeks.com/jsp-tutorials) - [JAX-RS Tutorials](https://www.javacodegeeks.com/jax-rs-tutorials) - [JAX-WS Tutorials](https://www.javacodegeeks.com/jax-ws-tutorials) - [JAXB Tutorials](https://www.javacodegeeks.com/jaxb-tutorials) - [JMS Tutorials](https://www.javacodegeeks.com/jms-tutorials) - [EJB Tutorials](https://www.javacodegeeks.com/ejb-tutorials) - [ElasticSearch Tutorials](https://www.javacodegeeks.com/elasticsearch-tutorials) - [JBoss Drools Tutorials](https://www.javacodegeeks.com/jboss-drools-tutorials) - [JMeter Tutorials](https://www.javacodegeeks.com/jmeter-tutorials) - [Apache Camel Tutorials](https://www.javacodegeeks.com/apache-camel-tutorials) - [Apache Hadoop Tutorials](https://www.javacodegeeks.com/apache-hadoop-tutorials) - [Java SLF4J Tutorials](https://www.javacodegeeks.com/java-slf4j-tutorials) - [CDI Tutorials](https://www.javacodegeeks.com/cdi-tutorials) - [Quartz Tutorials](https://www.javacodegeeks.com/quartz-tutorials) - [Desktop Java Tutorials](https://www.javacodegeeks.com/desktop-java-tutorials) - [AWT Tutorials](https://www.javacodegeeks.com/awt-tutorials) - [Java Swing Tutorials](https://www.javacodegeeks.com/java-swing-tutorials) - [JavaFX Tutorials](https://www.javacodegeeks.com/javafx-tutorials) - [Xuggler Tutorials](https://www.javacodegeeks.com/xuggler-tutorials) - [Eclipse IDE Tutorials](https://www.javacodegeeks.com/eclipse-ide-tutorials) - [IntelliJ IDEA Tutorials](https://www.javacodegeeks.com/intellij-idea-tutorials) - [Netbeans IDE Tutorials](https://www.javacodegeeks.com/netbeans-ide-tutorials) - [Android Tutorials](https://www.javacodegeeks.com/android-tutorials) - [Scala Tutorials](https://www.javacodegeeks.com/scala-tutorials) - [Play Framework Tutorials](https://www.javacodegeeks.com/play-framework-tutorials) - [DevOps Tutorials](https://www.javacodegeeks.com/devops-tutorials) - [Docker Tutorials](https://www.javacodegeeks.com/docker-tutorials) - [NoSQL Tutorials](https://www.javacodegeeks.com/nosql-tutorials) - [MongoDB Tutorials](https://www.javacodegeeks.com/mongodb-tutorials) - [Groovy Tutorials](https://www.javacodegeeks.com/groovy-tutorials) - [Git Tutorials](https://www.javacodegeeks.com/git-tutorials) - [Examples](https://examples.javacodegeeks.com/) - [Courses](https://courses.javacodegeeks.com/) - [Minibooks](https://www.javacodegeeks.com/minibook) - [Resources](https://www.javacodegeeks.com/resources) - [Java](https://www.javacodegeeks.com/best-java-programming-resources) - [Software](https://www.javacodegeeks.com/resources/software) - [Our Courses](https://www.javacodegeeks.com/courses) - [Our Projects](https://www.javacodegeeks.com/resources/our-projects) - [About](https://www.javacodegeeks.com/about) - [About JCGs](https://www.javacodegeeks.com/about/about-jcgs) - [Advertising](https://www.javacodegeeks.com/about/advertising) - [Terms of Use](https://www.javacodegeeks.com/about/terms-of-use) - [Privacy Policy](https://www.javacodegeeks.com/about/privacy-policy) - [Join Us](https://www.javacodegeeks.com/join-us) - [JCG](https://www.javacodegeeks.com/join-us/jcg) - [W4G](https://www.javacodegeeks.com/join-us/w4g) - [Submission Guidelines](https://www.javacodegeeks.com/join-us/w4g/submission-guidelines) - [Terms & Conditions](https://www.javacodegeeks.com/join-us/w4g/terms-conditions) - [Deals](https://deals.javacodegeeks.com/) - [RSS](https://feeds.feedburner.com/JavaCodeGeeks) - [Facebook](https://www.facebook.com/javacodegeeks) - [X](https://twitter.com/javacodegeeks) - [LinkedIn](https://www.linkedin.com/groups/3810709/) - [YouTube](https://www.youtube.com/channel/UCxoUc7Rar2q90Gu0nT2ffuQ) - [GitHub](https://github.com/javacodegeeks/) - [Menu](https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html) [![Java Code Geeks](https://www.javacodegeeks.com/wp-content/uploads/2012/12/JavaCodeGeeks-logo.png)](https://www.javacodegeeks.com/ "Java Code Geeks") - [Search for](https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html) - [Android](https://www.javacodegeeks.com/category/android) - [Android Core](https://www.javacodegeeks.com/category/android/android-core) - [Android Games](https://www.javacodegeeks.com/category/android/android-games) - [Java](https://www.javacodegeeks.com/category/java) - [Core Java](https://www.javacodegeeks.com/category/java/core-java) - [Desktop Java](https://www.javacodegeeks.com/category/java/desktop-java) - [Enterprise Java](https://www.javacodegeeks.com/category/java/enterprise-java) - [JVM Languages](https://www.javacodegeeks.com/category/jvm-languages) - [Ceylon](https://www.javacodegeeks.com/category/jvm-languages/ceylon) - [Clojure](https://www.javacodegeeks.com/category/jvm-languages/clojure) - [Groovy](https://www.javacodegeeks.com/category/jvm-languages/groovy) - [JRuby](https://www.javacodegeeks.com/category/jvm-languages/jruby) - [Kotlin](https://www.javacodegeeks.com/category/jvm-languages/kotlin) - [Scala](https://www.javacodegeeks.com/category/jvm-languages/scala) - [Soft Dev](https://www.javacodegeeks.com/category/software-development) - [Web Development](https://www.javacodegeeks.com/category/web-development) - [Python](https://www.javacodegeeks.com/category/web-development/python) - [JavaScript](https://www.javacodegeeks.com/category/web-development/javascript) - [React.js](https://www.javacodegeeks.com/category/web-development/javascript/react-js) - [Node.js](https://www.javacodegeeks.com/category/web-development/javascript/node-js) - [Angular](https://www.javacodegeeks.com/category/web-development/javascript/angular) - [jQuery](https://www.javacodegeeks.com/category/web-development/javascript/jquery) - [Vue.js](https://www.javacodegeeks.com/category/web-development/javascript/vue-js) - [TypeScript](https://www.javacodegeeks.com/category/web-development/typescript) - [PHP](https://www.javacodegeeks.com/category/web-development/php) - [Agile](https://www.javacodegeeks.com/category/agile) - [Career](https://www.javacodegeeks.com/category/career) - [Comms](https://www.javacodegeeks.com/category/communications) - [DevOps](https://www.javacodegeeks.com/category/devops) - [Blockchain](https://www.javacodegeeks.com/category/blockchain) - [Cardano](https://www.javacodegeeks.com/category/blockchain/cardano) - [Meta JCG](https://www.javacodegeeks.com/category/meta-jcg) - [Best Of The Week](https://www.javacodegeeks.com/category/meta-jcg/best-of-the-week) - [Misc](https://www.javacodegeeks.com/category/misc) [Home](https://www.javacodegeeks.com/)*»*[Java](https://www.javacodegeeks.com/category/java)*»*[Enterprise Java](https://www.javacodegeeks.com/category/java/enterprise-java)*»*Neo4j: COLLECTing multiple values [Enterprise Java](https://www.javacodegeeks.com/category/java/enterprise-java) # Neo4j: COLLECTing multiple values [![Photo of Mark Needham](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNDAiIGhlaWdodD0iMTQwIiB2aWV3Qm94PSIwIDAgMTQwIDE0MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![Photo of Mark Needham](https://secure.gravatar.com/avatar/5489baed26ce2d932bf951ecfb47afe80bec45d3648c23521d87c83b8f1c3ea9?s=140&d=mm&r=g)](https://www.javacodegeeks.com/author/Mark-Needham) [Mark Needham](https://www.javacodegeeks.com/author/Mark-Needham "Mark Needham") October 1st, 2014Last Updated: September 30th, 2014 0 223 2 minutes read One of my favourite functions in Neo4j’s cypher query language is COLLECT which allows us to group items into an array for later consumption. However, I’ve noticed that people sometimes have trouble working out how to collect multiple items with COLLECT and struggle to find a way to do so. Consider the following data set: ``` create (p:Person {name: "Mark"}) create (e1:Event {name: "Event1", timestamp: 1234}) create (e2:Event {name: "Event2", timestamp: 4567})   create (p)-[:EVENT]->(e1) create (p)-[:EVENT]->(e2) ``` If we wanted to return each person along with a collection of the event names they’d participated in we could write the following: ``` $ MATCH (p:Person)-[:EVENT]->(e) > RETURN p, COLLECT(e.name); +--------------------------------------------+ | p | COLLECT(e.name) | +--------------------------------------------+ | Node[0]{name:"Mark"} | ["Event1","Event2"] | +--------------------------------------------+ 1 row ``` That works nicely, but what about if we want to collect the event name and the timestamp but don’t want to return the entire event node? An approach I’ve seen a few people try during workshops is the following: ``` MATCH (p:Person)-[:EVENT]->(e) RETURN p, COLLECT(e.name, e.timestamp) ``` Unfortunately this doesn’t compile: ``` SyntaxException: Too many parameters for function 'collect' (line 2, column 11) "RETURN p, COLLECT(e.name, e.timestamp)" ^ ``` As the error message suggests, the COLLECT function only takes one argument so we need to find another way to solve our problem. One way is to put the two values into a literal array which will result in an array of arrays as our return result: ``` $ MATCH (p:Person)-[:EVENT]->(e) > RETURN p, COLLECT([e.name, e.timestamp]); +----------------------------------------------------------+ | p | COLLECT([e.name, e.timestamp]) | +----------------------------------------------------------+ | Node[0]{name:"Mark"} | [["Event1",1234],["Event2",4567]] | +----------------------------------------------------------+ 1 row ``` The annoying thing about this approach is that as you add more items you’ll forget in which position you’ve put each bit of data so I think a preferable approach is to collect a map of items instead: ``` $ MATCH (p:Person)-[:EVENT]->(e) > RETURN p, COLLECT({eventName: e.name, eventTimestamp: e.timestamp}); +--------------------------------------------------------------------------------------------------------------------------+ | p | COLLECT({eventName: e.name, eventTimestamp: e.timestamp}) | +--------------------------------------------------------------------------------------------------------------------------+ | Node[0]{name:"Mark"} | [{eventName -> "Event1", eventTimestamp -> 1234},{eventName -> "Event2", eventTimestamp -> 4567}] | +--------------------------------------------------------------------------------------------------------------------------+ 1 row ``` During the [Clojure Neo4j Hackathon](http://www.meetup.com/graphdb-london/events/194308602/) that we ran earlier this week this proved to be a particularly pleasing approach as we could easily destructure the collection of maps in our Clojure code. | | | |---|---| | Reference: | [Neo4j: COLLECTing multiple values](http://www.markhneedham.com/blog/2014/09/26/neo4j-collecting-multiple-values-too-many-parameters-for-function-collect/) from our [JCG partner](https://www.javacodegeeks.com/jcg/) Mark Needham at the [Mark Needham Blog](http://www.markhneedham.com/blog/) blog. | Do you want to know how to develop your skillset to become a Java Rockstar? Subscribe to our newsletter to start Rocking right now\! To get you started we give you our best selling eBooks for FREE\! 1\. JPA Mini Book 2\. JVM Troubleshooting Guide 3\. JUnit Tutorial for Unit Testing 4\. Java Annotations Tutorial 5\. Java Interview Questions 6\. Spring Interview Questions 7\. Android UI Design and many more .... I agree to the [Terms](https://www.javacodegeeks.com/about/terms-of-use) and [Privacy Policy](https://www.javacodegeeks.com/about/privacy-policy) [Sign up](https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html) ![](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMjAiIGhlaWdodD0iMzYzIiB2aWV3Qm94PSIwIDAgMzIwIDM2MyI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=) ![](https://www.javacodegeeks.com/wp-content/uploads/2015/01/books_promo.png) #### Thank you\! We will contact you soon. Tags [Neo4j](https://www.javacodegeeks.com/tag/neo4j) [![Photo of Mark Needham](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNDAiIGhlaWdodD0iMTQwIiB2aWV3Qm94PSIwIDAgMTQwIDE0MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![Photo of Mark Needham](https://secure.gravatar.com/avatar/5489baed26ce2d932bf951ecfb47afe80bec45d3648c23521d87c83b8f1c3ea9?s=140&d=mm&r=g)](https://www.javacodegeeks.com/author/Mark-Needham) [Mark Needham](https://www.javacodegeeks.com/author/Mark-Needham "Mark Needham") October 1st, 2014Last Updated: September 30th, 2014 0 223 2 minutes read [![Photo of Mark Needham](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxODAiIGhlaWdodD0iMTgwIiB2aWV3Qm94PSIwIDAgMTgwIDE4MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![Photo of Mark Needham](https://secure.gravatar.com/avatar/5489baed26ce2d932bf951ecfb47afe80bec45d3648c23521d87c83b8f1c3ea9?s=180&d=mm&r=g)](https://www.javacodegeeks.com/author/Mark-Needham) ### [Mark Needham](https://www.javacodegeeks.com/author/Mark-Needham) - [Website](http://www.markhneedham.com/blog/) ### Related Articles [![java-interview-questions-answers](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTAiIGhlaWdodD0iMTUwIiB2aWV3Qm94PSIwIDAgMTUwIDE1MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![java-interview-questions-answers](https://www.javacodegeeks.com/wp-content/uploads/2012/10/enterprise-java-logo.jpg)](https://www.javacodegeeks.com/2012/09/simple-rest-client-in-java.html) ### [Simple REST client in Java](https://www.javacodegeeks.com/2012/09/simple-rest-client-in-java.html) September 11th, 2012 [![spring-interview-questions-answers](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTAiIGhlaWdodD0iMTUwIiB2aWV3Qm94PSIwIDAgMTUwIDE1MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![spring-interview-questions-answers](https://www.javacodegeeks.com/wp-content/uploads/2012/10/spring-logo.jpg)](https://www.javacodegeeks.com/2019/05/error-creating-bean-datasource-datasourceautoconfiguration.html) ### [Spring Boot Error – Error creating a bean with name ‘dataSource’ defined in class path resource DataSourceAutoConfiguration](https://www.javacodegeeks.com/2019/05/error-creating-bean-datasource-datasourceautoconfiguration.html) May 1st, 2019 [![](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTAiIGhlaWdodD0iMTUwIiB2aWV3Qm94PSIwIDAgMTUwIDE1MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![](https://www.javacodegeeks.com/wp-content/uploads/2012/10/slf4j-logo.jpg)](https://www.javacodegeeks.com/2018/02/fix-exception-thread-main-java-lang-noclassdeffounderror-org-slf4j-loggerfactory-java.html) ### [How to fix Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in Java](https://www.javacodegeeks.com/2018/02/fix-exception-thread-main-java-lang-noclassdeffounderror-org-slf4j-loggerfactory-java.html) February 22nd, 2018 [![](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTAiIGhlaWdodD0iMTUwIiB2aWV3Qm94PSIwIDAgMTUwIDE1MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![](https://www.javacodegeeks.com/wp-content/uploads/2012/10/mockito-logo.jpg)](https://www.javacodegeeks.com/2020/07/mockito-cannot-instantiate-injectmocks-field-the-type-is-an-interface.html) ### [Mockito: Cannot instantiate @InjectMocks field: the type is an interface](https://www.javacodegeeks.com/2020/07/mockito-cannot-instantiate-injectmocks-field-the-type-is-an-interface.html) July 7th, 2020 [![spring-interview-questions-answers](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTAiIGhlaWdodD0iMTUwIiB2aWV3Qm94PSIwIDAgMTUwIDE1MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![spring-interview-questions-answers](https://www.javacodegeeks.com/wp-content/uploads/2012/10/spring-logo.jpg)](https://www.javacodegeeks.com/2020/04/spring-boot-remove-embedded-tomcat-server-enable-jetty-server.html) ### [Spring Boot Remove Embedded Tomcat Server, Enable Jetty Server](https://www.javacodegeeks.com/2020/04/spring-boot-remove-embedded-tomcat-server-enable-jetty-server.html) April 28th, 2020 [![spring-interview-questions-answers](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTAiIGhlaWdodD0iMTUwIiB2aWV3Qm94PSIwIDAgMTUwIDE1MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![spring-interview-questions-answers](https://www.javacodegeeks.com/wp-content/uploads/2012/10/spring-logo.jpg)](https://www.javacodegeeks.com/spring-interview-questions-and-answers.html) ### [100 Java Spring Interview Questions & Answers – The ULTIMATE List (PDF Download)](https://www.javacodegeeks.com/spring-interview-questions-and-answers.html) May 2nd, 2014 [![spring-interview-questions-answers](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTAiIGhlaWdodD0iMTUwIiB2aWV3Qm94PSIwIDAgMTUwIDE1MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![spring-interview-questions-answers](https://www.javacodegeeks.com/wp-content/uploads/2012/10/spring-logo.jpg)](https://www.javacodegeeks.com/2018/02/securitycontext-securitycontextholder-spring-security.html) ### [What is SecurityContext and SecurityContextHolder in Spring Security?](https://www.javacodegeeks.com/2018/02/securitycontext-securitycontextholder-spring-security.html) February 21st, 2018 [![java-interview-questions-answers](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTAiIGhlaWdodD0iMTUwIiB2aWV3Qm94PSIwIDAgMTUwIDE1MCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=)![java-interview-questions-answers](https://www.javacodegeeks.com/wp-content/uploads/2012/10/enterprise-java-logo.jpg)](https://www.javacodegeeks.com/2020/05/how-to-install-apache-web-server-on-ec2-instance-using-user-data-script.html) ### [How to install Apache Web Server on EC2 Instance using User data script](https://www.javacodegeeks.com/2020/05/how-to-install-apache-web-server-on-ec2-instance-using-user-data-script.html) May 7th, 2020 Subscribe This site uses Akismet to reduce spam. [Learn how your comment data is processed.](https://akismet.com/privacy/) 0 Comments Oldest Newest Most Voted Inline Feedbacks View all comments Join Us ![Join Us](https://www.javacodegeeks.com/wp-content/uploads/2013/04/w4g-badge-150x150.png) With 1,240,600 monthly unique visitors and over 500 authors we are placed among the top Java related sites around. Constantly being on the lookout for partners; we encourage you to join us. So If you have a blog with unique and interesting content then you should check out our **[JCG](https://www.javacodegeeks.com/join-us/jcg)** partners program. You can also be a **[guest writer](https://www.javacodegeeks.com/join-us/w4g)** for Java Code Geeks and hone your writing skills\! Newsletter ![](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMzUiIGhlaWdodD0iMzEwIiB2aWV3Qm94PSIwIDAgMzM1IDMxMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idHJhbnNwYXJlbnQiLz48L3N2Zz4=) ![](https://www.javacodegeeks.com/wp-content/uploads/2018/01/newsletter-bg.jpg) Insiders are already enjoying weekly updates and complimentary whitepapers\! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, JVM languages, cloud computing, Web development, DevOps, big data, Web3, blockchain programming and other related technologies. Email address: I agree to the [Terms](https://www.systemcodegeeks.com/about/terms-of-use/) and [Privacy Policy](https://www.javacodegeeks.com/about/privacy-policy/) [Sign up](https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html) #### Thank you\! We will contact you soon. Knowledge Base - [Courses](https://courses.javacodegeeks.com/) - [Examples](https://examples.javacodegeeks.com/) - [Minibooks](https://www.javacodegeeks.com/minibook) - [Resources](https://www.javacodegeeks.com/resources) - [Tutorials](https://www.javacodegeeks.com/tutorials) The Code Geeks Network - [.NET Code Geeks](https://www.dotnetcodegeeks.com/) - [Java Code Geeks](https://www.javacodegeeks.com/) - [System Code Geeks](https://www.systemcodegeeks.com/) - [Web Code Geeks](https://www.webcodegeeks.com/) Hall Of Fame - [“Android Full Application Tutorial” series](https://www.javacodegeeks.com/2010/10/android-full-application-tutorial.html) - [11 Online Learning websites that you should check out](https://www.javacodegeeks.com/2013/01/15-online-learning-websites-that-you-should-check-out.html) - [Advantages and Disadvantages of Cloud Computing – Cloud computing pros and cons](https://www.javacodegeeks.com/2013/04/advantages-and-disadvantages-of-cloud-computing-cloud-computing-pros-and-cons.html) - [Android Google Maps Tutorial](https://www.javacodegeeks.com/2011/02/android-google-maps-tutorial.html) - [Android JSON Parsing with Gson Tutorial](https://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html) - [Android Location Based Services Application – GPS location](https://www.javacodegeeks.com/2010/09/android-location-based-services.html) - [Android Quick Preferences Tutorial](https://www.javacodegeeks.com/2011/01/android-quick-preferences-tutorial.html) - [Difference between Comparator and Comparable in Java](https://www.javacodegeeks.com/2013/03/difference-between-comparator-and-comparable-in-java.html) - [GWT 2 Spring 3 JPA 2 Hibernate 3.5 Tutorial](https://www.javacodegeeks.com/2010/05/gwt-2-spring-3-jpa-2-hibernate-35-2.html) - [Java Best Practices – Vector vs ArrayList vs HashSet](https://www.javacodegeeks.com/2010/08/java-best-practices-vector-arraylist.html) About Java Code Geeks JCGs (Java Code Geeks) is an independent online community focused on creating the ultimate Java to Java developers resource center; targeted at the technical architect, technical team lead (senior developer), project manager and junior developers alike. JCGs serve the Java, SOA, Agile and Telecom communities with daily news written by domain experts, articles, tutorials, reviews, announcements, code snippets and open source projects. Disclaimer All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners. Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. Examples Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation. Java Code Geeks and all content copyright © 2010-2026, [Exelixis Media P.C.](https://www.exelixismedia.com/) \| [Terms of Use](https://www.javacodegeeks.com/about/terms-of-use) \| [Privacy Policy](https://www.javacodegeeks.com/about/privacy-policy) \| [Contact](mailto:support@javacodegeeks.com) \| Do not share my Personal Information \| [Cookie Settings]() - [RSS](https://feeds.feedburner.com/JavaCodeGeeks) - [Facebook](https://www.facebook.com/javacodegeeks) - [X](https://twitter.com/javacodegeeks) - [LinkedIn](https://www.linkedin.com/groups/3810709/) - [YouTube](https://www.youtube.com/channel/UCxoUc7Rar2q90Gu0nT2ffuQ) - [GitHub](https://github.com/javacodegeeks/) [Facebook](https://www.facebook.com/sharer.php?u=https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html "Facebook") [X](https://x.com/intent/post?text=Neo4j%3A%20COLLECTing%20multiple%20values&url=https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html "X") [WhatsApp](https://api.whatsapp.com/send?text=Neo4j%3A%20COLLECTing%20multiple%20values%20https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html "WhatsApp") [Telegram](https://telegram.me/share/url?url=https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html&text=Neo4j%3A%20COLLECTing%20multiple%20values "Telegram") [Back to top button](https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html#go-to-tie-body) [Close](https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html) - [RSS](https://feeds.feedburner.com/JavaCodeGeeks) - [Facebook](https://www.facebook.com/javacodegeeks) - [X](https://twitter.com/javacodegeeks) - [LinkedIn](https://www.linkedin.com/groups/3810709/) - [YouTube](https://www.youtube.com/channel/UCxoUc7Rar2q90Gu0nT2ffuQ) - [GitHub](https://github.com/javacodegeeks/) [Close](https://www.javacodegeeks.com/2014/10/neo4j-collecting-multiple-values.html) wpDiscuz Insert
Readable Markdown
One of my favourite functions in Neo4j’s cypher query language is COLLECT which allows us to group items into an array for later consumption. However, I’ve noticed that people sometimes have trouble working out how to collect multiple items with COLLECT and struggle to find a way to do so. Consider the following data set: ``` create (p:Person {name: "Mark"}) create (e1:Event {name: "Event1", timestamp: 1234}) create (e2:Event {name: "Event2", timestamp: 4567})   create (p)-[:EVENT]->(e1) create (p)-[:EVENT]->(e2) ``` If we wanted to return each person along with a collection of the event names they’d participated in we could write the following: ``` $ MATCH (p:Person)-[:EVENT]->(e) > RETURN p, COLLECT(e.name); +--------------------------------------------+ | p | COLLECT(e.name) | +--------------------------------------------+ | Node[0]{name:"Mark"} | ["Event1","Event2"] | +--------------------------------------------+ 1 row ``` That works nicely, but what about if we want to collect the event name and the timestamp but don’t want to return the entire event node? An approach I’ve seen a few people try during workshops is the following: ``` MATCH (p:Person)-[:EVENT]->(e) RETURN p, COLLECT(e.name, e.timestamp) ``` Unfortunately this doesn’t compile: ``` SyntaxException: Too many parameters for function 'collect' (line 2, column 11) "RETURN p, COLLECT(e.name, e.timestamp)" ^ ``` As the error message suggests, the COLLECT function only takes one argument so we need to find another way to solve our problem. One way is to put the two values into a literal array which will result in an array of arrays as our return result: ``` $ MATCH (p:Person)-[:EVENT]->(e) > RETURN p, COLLECT([e.name, e.timestamp]); +----------------------------------------------------------+ | p | COLLECT([e.name, e.timestamp]) | +----------------------------------------------------------+ | Node[0]{name:"Mark"} | [["Event1",1234],["Event2",4567]] | +----------------------------------------------------------+ 1 row ``` The annoying thing about this approach is that as you add more items you’ll forget in which position you’ve put each bit of data so I think a preferable approach is to collect a map of items instead: ``` $ MATCH (p:Person)-[:EVENT]->(e) > RETURN p, COLLECT({eventName: e.name, eventTimestamp: e.timestamp}); +--------------------------------------------------------------------------------------------------------------------------+ | p | COLLECT({eventName: e.name, eventTimestamp: e.timestamp}) | +--------------------------------------------------------------------------------------------------------------------------+ | Node[0]{name:"Mark"} | [{eventName -> "Event1", eventTimestamp -> 1234},{eventName -> "Event2", eventTimestamp -> 4567}] | +--------------------------------------------------------------------------------------------------------------------------+ 1 row ``` During the [Clojure Neo4j Hackathon](http://www.meetup.com/graphdb-london/events/194308602/) that we ran earlier this week this proved to be a particularly pleasing approach as we could easily destructure the collection of maps in our Clojure code. [![Photo of Mark Needham](https://secure.gravatar.com/avatar/5489baed26ce2d932bf951ecfb47afe80bec45d3648c23521d87c83b8f1c3ea9?s=180&d=mm&r=g)](https://www.javacodegeeks.com/author/Mark-Needham)
Shard27 (laksa)
Root Hash14334457447596406227
Unparsed URLcom,javacodegeeks!www,/2014/10/neo4j-collecting-multiple-values.html s443