Troubleshooting MongoDB Connection Failure

Source: Internet
Author: User

MongoDB was installed, user Rex with admin root and test database added, and user authentication turned on.

Connect to the MongoDB database as documented: $mongo = new MONGO ("Mongodb://rex:[email protected]");

Results found error after opening firebug: "networkerror:500 Internal Server error-http://192.168.202.132/montest.php"

There are a lot of ways to try it out, and it's unclear why it went wrong, only to read the official PHP document (http://php.net/manual/zh/mongoclient.construct.php)

By chance you see this: if the given host is unable to connect, the Mongoconnectionexception exception will be thrown.

So I started trying to print the exception:

try {     $mongo = new MONGO ("Mongodb://rex:[email protected]"), catch (Exception $e) {     print $e->getmessage (); C2/>exit ();   

The output is: Failed to connect to:localhost:27017:authentication Failed on database ' admin ' with username ' Rex ': Auth Failed

A look at it: Rex is the user of the test database, but the code is indeed the default connection to the database admin, the problem is here!

Then change to: $mongo = new MONGO ("Mongodb://rex:[email protected]/test");

Problem Solving!


Troubleshooting MongoDB Connection Failure

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.