In this exercise, setting one of properties (conditional on another property) to something is a goal in itself, so I don't consider using just one having all values.
My mistake. The error made me remember that you can't set a parameter dynamically with the bracket syntax. Here is an approach using apoc.
MATCH ( n: Person )
WITH n,
CASE
WHEN n.age > 60 THEN 'old'
WHEN 60 > n.age > 30 THEN 'middle'
ELSE 'young'
END as property
call apoc.cypher.doIt("set n." + property + " = true", {n:n}) yield value
return value
It might be even better to set it as a label.
You can use apoc.create.addLabel(node,[labels]) for that.
Which then also allows for more efficient matching.
MATCH
( n: Person )
call apoc.create.addLabels(n, [
CASE
WHEN n.age > 60 THEN 'old'
WHEN 60 > n.age > 30 THEN 'middle'
ELSE 'young'
END]) yield node
return count(*);
Nevertheless I wonder why using apoc.cypher.doIt() that incorporates SET clause, even though properties have been set, I receive "No changes, no records" message? I would expect "Set x properties" in return.
I suspect it is because the SET operation is occurring on the backend via the apoc procedure, so the executor is not aware of the impact of the 'doit' cypher statement.