Number of distinct elements in an array property

(Mikepalei) #1

Is it possible to calculate a number of distinct elements of an array property per each node?

0 Likes

(Michael Hunger) #2

yes if you get the elements, then you can use count(distinct e)

for your example:

match (p:Person)
where p.id in ["1", "2"]
unwind p.embed as e
return p, count(distinct e)

or you can use size(apoc.coll.toSet(p.embed))

1 Like