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

connecting mongodb with authorization feature

Hi,

I have enabled authorization feature in mongodb. How do I connect mongodb with username and password.

phalcon

$di->set('mongo', function() use ($config) { $mongo = new MongoClient("mongodb://" . $config->dbclient->username . ":" . $config->dbclient->password . "@" . $config->dbclient->host, array("db" => $config->dbclient->dbname)); return $mongo->selectDB($config->dbclient->dbname); }, true);

Config

[dbclient] dbname = datadb host = localhost username = user password = 'test1234';

Error Message

2017-08-08T23:14:22.612-0400 I NETWORK [initandlisten] connection accepted from 127.0.0.1:38859 #60 (3 connections now open) 2017-08-08T23:14:22.619-0400 I ACCESS [conn60] SCRAM-SHA-1 authentication failed for user on angel from client 127.0.0.1 ; UserNotFound: Could not find user [email protected] PHP Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: SASL Authentication failed on database 'angel': Authentication failed.' in /var/www/html/angel/cli/cli.php:51 Stack trace:

The username "user", I am having it in admin auth. Please suggest me on the same

Raja K

edited Aug '17

Server connection should have the form: mongodb://[username:[email protected]]host1[:port1][,host2[:port2:],...]/db

UserNotFound - you're obviously supplying wrong user?