Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Get a Model's Mongo connection

I want to get the Mongo Connection of a Model inside a Controller and use the native findOne or other Mongo Queries on my collection, is there any way to do that?



84.4k
Accepted
answer

You can create a method that makes the internal _getCollection visible to the public:

class Users extends Phalcon\Mvc\Collection
{
    public function getCollection()
    {
        return $this->getConnection()->selectCollection('users');
    }
}