'Can't retrieve identity and labels after collect + unwind in cypher

I'm working on a pretty complex query which involves some unwinds and collects, and mixes together different types of nodes. At the end of it, I'm left with a list of maps. When I just return the list, I see that each element has the attributes identity, labels, and properties.

However, I don't seem to be able to retrieve the value of identity and labels through the key, map_element.identity, nor with map_element["identity"]. I've tried using the functions ID and labels but it gives me the error that the element is a map and not a node.

Basic query to test on any data to see what I mean:

MATCH (a), (b)
WITH collect(a) + collect(b) as collected
UNWIND collected as unwinded
RETURN unwinded, unwinded.identity

You will notice that in the unwinded column, identity, labels, and properties are present, however unwinded.identity is null



Solution 1:[1]

Did you try id(unwinded) and labels(unwinded) ?

Solution 2:[2]

ID function is the equivalence of getting that identity property:

https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-id

For labels, it is the same labels function: https://neo4j.com/docs/cypher-manual/current/functions/list/#functions-labels

MATCH (a), (b)
WITH collect(a) + collect(b) as collected
UNWIND collected as unwinded
RETURN unwinded, ID(unwinded), unwinded.<property>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Graphileon
Solution 2 jose_bacoy