How to collect node property and relationship property together


(Henry Macafee) #1

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


What I'd like to return is something like:,, {}
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

(Andrew Bowman) #2

The tricky part of this is that with Cypher alone you cannot create a map with a dynamic property key (, 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 as creator, as item, b
MATCH (c:User)-[r:PURCHASED]->(b)
RETURN creator, item,[], []) as purchaser

(Henry Macafee) #3

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