Is it possible to write condition in Collect?

(Abhishinde01) #1

Return COLLECT({type:labels(t), id:t.userid,id:t.teamid}) as tagged

Here based on label type can we make id parameter in dynamic in collection result?
Like if type = User then id:t.userid
if type = Team then id:t.teamid

(Andrew Bowman) #2

You can use CASE here to do this:

RETURN collect({type:labels(t), id: CASE WHEN t:User THEN t.userid ELSE t.teamid END}) as tagged

Alternately you can use coalesce() to get the first non-null result:

RETURN collect({type:labels(t), id: coalesce(t.userid, t.teamid)}) as tagged