Hello neo4j people,
this is quite probably a newbie question but I haven't found anything on the subject here/internet.
(With map I mean object (js), dictionary, key/value-pair)
Setup DB: CREATE (n:Node {prop1: 'val1', prop2: 'val2'})
.
When one wants a specific subset of the props one can obviously do something like:
UNWIND ['prop1', 'prop2', 'prop3'] as k, MATCH (n:Note) RETURN [k, n[k]]
This shall give the result: [['prop1', 'val1'], ['prop2', 'val2'], ['prop3', null]]
As maps and map accessors are obviously supported I was wondering whether it's possible to also get this result back in a map, so : {prop1: 'val1', prop2: 'val2', prop3: null}
.
As it's possible to do something like WITH {a: 'hello'} as map1 RETURN map1
which is {a: 'hello'}
I tried to do the following WITH {} as result UNWIND ['prop1', 'prop2', 'prop3'] as k, MATCH (n:Note) SET result[k] = n[k] RETURN k
Unfortunately this doesn't work as SET only works on nodes. I also tried setProperty of apoc: apoc.create.setProperty - APOC Extended Documentation but this also only works on nodes. So I have two questions:
- How would one return a map instead of a list naturally in cypher?
- When creating a map and accessing maps is both supported in cypher and given that cypher makes apparently no differentiation between accessing a map and accessing a node, how can one set a value in a map?
Thank you for your time
Timon