We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Fatal error: Class 'mongoid' not found in

PHP 7, Mongo 3, Phalcon 3 incubator library 3.4 from https://github.com/phalcon/incubator/releases

PROBLEM: trying to connect to mongo. In controller when i run ->save() i get fatal error ... Fatal error: Class 'mongoid' not found in


            # bootstrap
            $mongo = new MongoClient($dburl);
            return $mongo->selectDatabase($dbname);
            # controller...
            $user = new \MyApp\Models\Users();
            $user->email    = $this->request->getPost('email', 'striptags');
            $user->name = $this->request->getPost('name', 'striptags');
            $user->password = $this->security->hash($this->request->getPost('password'));

Any ideas on how to fix?

edited Sep '18

This helped...

instead of...

use Phalcon\Mvc\Collection;


use Phalcon\Mvc\MongoCollection;
class Somedata extends MongoCollection{
public function initialize()
    // set actual collection name

I also had to add the db name to the end of the connection string or i got authentication failure...

$di->setShared('mongo', function () {
        $mongo = new MongoClient('mongodb://mongousername:[email protected]:12345/mongodbname');
        return $mongo->selectDatabase('mongodbname');