# Conditional apoc.map.setKey

(Nikolai) #1

Hi!

I was trying to conditionally set a key using apoc.map.setKey but am not getting it to work.
How would I go about doing something like

if value.selection is not null
apoc.map.setKey(n, 'who', {filter: value.selection, type: type})

Any hints would be very much appreciated!

Nikolai

(Michael Hunger) #2

You can use WHERE for a general filter or perhaps CASE

WITH CASE value.selection WHEN null THEN map ELSE apoc.map.setKey(map, 'who', {filter: value.selection, type: type}) END as map

(Nikolai) #3

Thanks a lot! This works well!