cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Is it possible to write condition in Collect?

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

1 ACCEPTED SOLUTION

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

View solution in original post

1 REPLY 1

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