# How to get just the result set count?
- Construct the query using the collection's QueryBuilder class
- use the
countapi to read the count.
For example:
val lotteryQry = LotteryQuery().open.is(true).lotteryName.startsWith("metastay")
val noOfMatchedRows = lotteryQry.count
Common mistake: using find with List's size to do the same, for example:
val lotteryQry = LotteryQuery().open.is(true).lotteryName.startsWith("metastay")
val noOfMatchedRows = lotteryQry.find.size // too expensive, use lotteryQuery.count instead
This reads the entire resultset from db on to memory, when all that is needed is to fetch just the count.