ODM pagination

I'm rolling my own pagination for my models.

What is the preferred way to get the total count when making a limited, skipped find()?

Getting the whole result and then just taking the required objects seems wasteful, especially when I only need the first 20 of 10,000 records.

Thanks



3.6k

Figured this out myself.

Made this method on my Collection:

public static function countQuery($arr) {
    $coll = new self();
    return self::_getGroupResultset($arr, $coll, $coll->getConnection());
}

I call this to get my total count then add the limit and skip parameters to my query for the results I need.



11.3k

Hi, Ty Kroll!

What's usecase for that?