Hi,

I got the below exception while configuring mongodb with phalcon. Can you please suggest me what I did wrong.

[Sun Jan 20 07:22:11.039065 2019] [php7:error] [pid 3942] [client 103.253.168.194:30134] PHP Fatal error:  Uncaught Error: Call to undefined function #0 [internal function]: Phalcon\\Di->get('db', NULL)\n#1 [internal function]: Phalcon\\Di->getShared('db')\n#2 [internal function]: Phalcon\\Mvc\\Model\\Manager->_getConnection(Object(PhalconRest\\Models\\User), NULL)\n#3 [internal function]: Phalcon\\Mvc\\Model\\Manager->getReadConnection(Object(PhalconRest\\Models\\User))\n#4 [internal function]: Phalcon\\Mvc\\Model->getReadConnection()\n#5 [internal function]: Phalcon\\Mvc\\Model\\Query->getReadConnection(Object(PhalconRest\\Models\\User), Array, NULL, NULL)\n#6 [internal function]: Phalcon\\Mvc\\Model\\Query->_executeSelect(Array, NULL, NULL)\n#7 [internal function]: Phalcon\\Mvc\\Model\\Query->execute()\n#8 /var/www/html/app/admin/backend/api/controllers/UserController.php(111): Phalcon\\Mvc\\Model::find()\n#9 [internal function]: PhalconRest\\Controllers\\UserController->listuser()\n#10 [internal function]: Phalcon\\Mvc\\Micro\\LazyLoader->__call('listuser', Array)\n#11 [internal function]: Phalcon\\Mvc\\Micro\\LazyLoader->callMethod('listuser', Arr in /var/www/html/app/admin/backend/api/config/init.php on line 43

Below is my service,

use \Phalcon\Db\Adapter\MongoDB\Client as DBClient;
$di->set('mongo', function() use ($config) {
$mongo = new DBClient("mongodb://" . $config->dbclient->username . ":" . $config->dbclient->password . "@" . $config->dbclient->host, array("db" => $config->dbclient->authdb));
return $mongo->selectDatabase($config->dbclient->dbname);
}, true);
  • Raja K