Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-10-2018 02:19 PM
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
12-10-2018 03:10 PM
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
12-10-2018 03:27 PM
Awesome, I think this did the trick. Thank you!
All the sessions of the conference are now available online