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.

How to count number of elements in a list?

I am trying to count the number of elements in a list

UNWIND [{id:'0001',name:'Test',size:'10mm'}] as rows
RETURN count(rows)

However this always returns 1. For this example the return value should be 3, even if the list is empty then it should return 0.

1 ACCEPTED SOLUTION

Your datastructure is a 1-element array containing a map with 3 elements.

This returns 3:

unwind [{id:'0001',name:'Test',size:'10mm'}] as map
return size(keys(map))

You cannot apply size on a map, therefore use keys() to get an array of keys from the map.

View solution in original post

2 REPLIES 2

Your datastructure is a 1-element array containing a map with 3 elements.

This returns 3:

unwind [{id:'0001',name:'Test',size:'10mm'}] as map
return size(keys(map))

You cannot apply size on a map, therefore use keys() to get an array of keys from the map.

Thanks for the help stefen.armbruster