connecting mongodb with authorization feature


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


$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);


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

Error Message

2017-08-08T23:14:22.612-0400 I NETWORK [initandlisten] connection accepted from #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 ; 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?