I want to add a value to an array if its not already there.
So far my code looks something like this (note that both r.names and {name} are arrays, and [1] + [2] = [1,2]
):
MERGE (r:resource {hash:{hash}})
ON CREATE SET r.names = {name}
ON MATCH SET r.names = r.names + {name}
but obviously if {name}
is already in r.names
, it just gets added again. How can I add {name}
only if r.names
doesn't already contain it?