Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-21-2022 06:50 AM
Just in case I've missed it in the docs: is there something like spread operators for map projections?
I have two related nodes, which I would get with MATCH (b:Building)--(a:Address)
.
Now I can project the address into the building with RETURN b{.*, id: ID(b), address: a} AS building;
But is it possible to flatten the map and add the properties of Address to the new map without referencing them one by one?
We could have apoc.create.virtual.fromNode(node :: NODE?, propertyNames :: LIST? OF STRING?)
(from docs) for multiple nodes, maybe with some property configuration like it is supposed to work in nodes.collapse
(which seems to live in a completely different domain).
Or we could have some spread operator like RETURN b{.*, id: ID(b), ..a} AS building;
.
Solved! Go to Solution.
04-21-2022 09:01 AM
If that does not work for you, and you really want a flat map, apoc has some procedures:
Merge two maps (just merges the key/value pairs):
with b{.*, id: id(b)} as bMap, properties(a) as aMap
return apoc.map.merge( bMap, aMap)
Flatten a map (uses dot notation to merge key/values):
with b{.*, id: id(b), address: properties(a)} as map
return apoc.map.flatten( map)
or, if you want each node to be prefixed:
with {id: id(b), building: properties(b), address: properties(a)} as map
return apoc.map.flatten( map)
04-21-2022 08:22 AM
Sure, try:
RETURN b{.*, id: ID(b), address: properties(a)}
04-21-2022 09:01 AM
If that does not work for you, and you really want a flat map, apoc has some procedures:
Merge two maps (just merges the key/value pairs):
with b{.*, id: id(b)} as bMap, properties(a) as aMap
return apoc.map.merge( bMap, aMap)
Flatten a map (uses dot notation to merge key/values):
with b{.*, id: id(b), address: properties(a)} as map
return apoc.map.flatten( map)
or, if you want each node to be prefixed:
with {id: id(b), building: properties(b), address: properties(a)} as map
return apoc.map.flatten( map)
04-26-2022 07:19 AM
Ah, map.merge
and map.flatten
do look promising. Thanks!
All the sessions of the conference are now available online