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.