0
votes

I've been getting this error and can't find a solution.

I have mongoDB installed on a Ubuntu server along with PHP, the installation is working fine, and I can access mongo thru the terminal (SSH with putty) with no problem, but, when I try to access it thru any PHP application I get the "No candidate servers found" even though the log says that the connection was accepted.

I tried setting up the bind_ip to the server ip, to 127.0.0.1, to localhost and nothing is working.

extra info: - I'm running in standalone mode. - starting mongo with mongod --fork --auth --port 27017 --logpath /var/log/mongodb/server1.log --logappend --dbpath /var/lib/mongodb/data/db/

Does anyone have any ideia?

Thanks.

1
driver version and MongoDB version?Sammaye
My phpinfo says: Version 1.4.3user1111718
How have you configured your application? Its error denotes it is trying to connect to a replica setSammaye
I would enable full debug logging (us2.php.net/mongolog.setcallback) to track what exactly is going on in the driver. I suspect your connection string may be wrong... How exactly are you instantiating MongoClient?bjori

1 Answers

0
votes

This error seems to occur for me when I am running MongoDB with replication (the replSet option), and there are no primary servers available for some reason.

For instance, after restarting the Primary the selection of a new Primary seems to take a while, with nothing but Secondary's available.

You said you are not running with replication though, but are in "standalone" mode... in that case, other questions I have seen suggest making sure you are running up-to-date MongoDB and PHP driver versions (from the Ubuntu 10gen apt-get source). Also double check that you can access mongo from the same server PHP is on in case there are firewall issues: mongo mongohost1.server.com:27107 -uUSERNAME -pPASSWORD

It would be helpful to see the connection string you are passing in to the MongoClient() PHP driver. It will look something like this if you are not using replication:

mongodb://USERNAME:PASSWORD@localhost:27017

And will look something like this if you are using replication:

mongodb://USERNAME:[email protected]:27017,host2.server.com:27017,host3.server.com:27017/?replicaSet=my_replica_set

If you are using replication, make sure that you specify the Primary Mongodb server as one of the servers (the driver should detect which one is the Primary, and detect if the Primary changes).

If that is all set up correctly, double check that you do in fact have a Primary. There could be something wrong, causing MongoDB not to elect a Primary. You can log to the Mongo commandline/console app and run this to check the status of all replica set members:

rs.status()

I am running PHP 5.3, MongoDB 2.4.8, MongoDB PHP Driver 1.4.5, Ubuntu 12.04.

(I assume this old post got solved somehow, but I just found myself here with a similar issue so I thought I might provide an answer to help people in the future troubleshoot their issues.