We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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?



98.9k
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');
    }
}