.countPercent()
The result is always returned as a Percent, calculated as (number of items that match the criteria) divided by (total number of items).
Syntax
.count{expression}
- Returns the percentage of items in the Sequence or List where the expression evaluates to a truthy value
Examples
- [1, 2, 3, 4].countPercent{it >= 3} returns 50%
- db.job.find().countPercent{dept:engineering} returns the percentage of all jobs in the organization that are in the Engineering department.
- db.job.find{dept:engineering gender:*}.countPercent{gender:female} returns the percentage of Female-identified people, taken as a percentage of people in the Engineering department who have specified their gender.
