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