cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to collect node property and relationship property together

Hi there! I'm trying to return what I can only best describe as a subquery. For example:

(a:User)-[:CREATED]->(b:Item)
(c:User)-[r:PURCHASED]->(b)

What I'd like to return is something like:
a.name, b.name, {c.name: r.date}
as there are multiple c:nodes and r:relationships per b:node.

I've looked into map projections but keep hitting a dead end. Any suggestions?

Thank you for your time

2 REPLIES 2

The tricky part of this is that with Cypher alone you cannot create a map with a dynamic property key (c.name), it has to be literal.

There is a workaround you can use with helper functions from APOC Procedures, but make sure you actually need this as it complicates the query.

MATCH (a:User)-[:CREATED]->(b:Item) 
WITH a.name as creator, b.name as item, b
MATCH (c:User)-[r:PURCHASED]->(b)
RETURN creator, item, apoc.map.fromLists([c.name], [r.date]) as purchaser

Awesome, I think this did the trick. Thank you!