Is there a fancy or tricky way to apply an arbitrary array of jsonpatch-like to maps with cypher or even apoc?
So if i have
- a map
{a: 0, b: 0, c: 0}
- a collection of operations encoded in maps, say
[{replace: "a", value: 1}, {replace: "b", value: 1}]
. I know it's not rellay jsonpatch but it's all I need. If there is a fully fledged jsonpatch solution, even better.
I seek a procedure, a concatenation of procedures or a neat way in cypher that produces {a: 1, b: 1, c: 0}
There is apoc.map.setKey(map, key, value)
found in https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_map_functions but that only manipulates one value at once. I tried combining that with cypher's FOREACH
but I need to indeed mutate a map and not a node.
my try was
create (:TEST {a: 0, b: 0, c: 0});
match (t:TEST)
with t, [{replace: "a", value: 1}, {replace: "b", value: 1}] as refs
foreach(ref in refs
| set t = apoc.map.setKey(properties(t), ref.replace,
ref.value))
return *;
Of course I could always let the client do the jsonpatch operations, but I prefer a way to do it within the tx. I know I could also write a procedure myself as a last resort.