简体   繁体   中英

mongoDB authentication error

I'm new at mongoDB and am trying to connect using php driver..

this is my code :

$this->connection = new Mongo("mongodb://tatao_user:tatao_pass@ds043047.mongolab.com:43047/tatao"); 

but it didn't work and resulting in the error below :

Fatal error: Uncaught exception 'MongoConnectionException' with message 'Couldn't authenticate with database tatao: username [tatao_user]'

I've also tried using the shell, but the reuslt is the same.

please help....

Thx B4...

First of all you need to check if mongodb is running and you have no errors.

Then if you are sure your credential (user and password) are right try this:

<?php

$mongo = new Mongo();

$db = $mongo->db_name; //replace db_name with your db name obviously

$username = "myuser";
$password = "mypassword";

$db->authenticate($username, $password);

?>

you should also check the manual: http://php.net/manual/en/mongo.connecting.php

Then, i use Codeigniter too, and there is a really good library for mongodb , simple and fast, using Active Records and all the staffs as for the standard database library of CI. I really suggest you to use that, you can check that here:

https://github.com/alexbilbie/codeigniter-mongodb-library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM