tiaguinho / mongodb-cakephp3

An Mongodb datasource for CakePHP 3.0
MIT License
28 stars 29 forks source link

No efficient way of counting? #28

Closed johnjcamilleri closed 5 years ago

johnjcamilleri commented 5 years ago

I wanted an equivalent of Mongo's count command, which can return a result count without having to perform an actual find (which can be much slower). I couldn't find it in this library, so I hacked together this, added to src/ORM/Table.php:

/**
 * count documents
 *
 * @param array $options
 * @return int
 * @access public
 */
public function count($options = [])
{
    $query = new MongoFinder($this->__getCollection(), $options);
    return $query->connection()->count();
}

Not sure if I've missed something, seems like this functionality should be standard?

tiaguinho commented 5 years ago

Hi @johnjcamilleri, can you open a PR with this change so I can merge with the master of the project?

Thanks!

tiaguinho commented 5 years ago

Thank you for your contribution @johnjcamilleri