2

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

this is my code :

$this->connection = new Mongo("mongodb://tatao_user:[email protected]: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...

1
  • It may sound obvious but are you sure you are putting in the right username and pw? Have you tried pinging ds043047.mongolab.com:43047 to see if it responds as it should? Commented Nov 16, 2012 at 12:32

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I've used the codeigniter library and still can't connect to it. the authenticate function is depricated and it gives error.
@Jason damn, i used that months ago maybe they changed somenthing, anyway the lib has a good mongodb.php config file you checked that right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.