Troubleshoot mongodb connection failure
Install mongodb, add the administrator root and test Database User rex, and enable user authentication.
Follow the instructions to connect to the mongodb Database: $ mongo = new Mongo ("mongodb: // rex: 123456 @ localhost ");
The Error "NetworkError: 500 Internal Server Error-http: // 192.168.202.132/montest. php" is reported when firebug is enabled"
Here I tried a lot of methods can not solve, it is not clear why the error, can only look at the official documents of php (http://php.net/manual/zh/mongoclient.construct.php)
If the given host cannot be connected, the mongoonexception will be thrown.
So I started to print this exception:
try { $mongo = new Mongo("mongodb://rex:123456@localhost"); } catch (Exception $e) { print $e->getMessage(); exit(); }
The output result is: Failed to connect to: localhost: 27017: Authentication failed on database 'admin' with username 'rex ': auth failed.
At first glance, we can see that rex is a user of the test database, but the Code does connect to the database admin by default. The problem lies here!
Changed to: $ mongo = new Mongo ("mongodb: // rex: 123456 @ localhost/test ");
Solve the problem!
Mongodb cannot be started, and cannot be connected because the target computer is actively rejected.
This is not because mongodb cannot be started. If you haven't started mongodb, you can connect to it and use it. It is definitely not successful.
Run mongod -- dbpath XXXX/data in the bin directory of mongodb to start mongodb, and then connect to mongodb.
An error occurred while connecting Mongodb to the internet server. There is no problem connecting to the LAN server.
Check the bind_ip parameter because the mongoDB server is bound with an intranet IP address, so it cannot be accessed from the Internet.