I am running my website with Laravel 5 + MongoDB.

I am using mongo cluster to speed up data read and write, and to lower CPU usage of the mongo server.

I have set up the replica like this: is primary replica set, and & is the secondary replica set.

Config::set('database.connections.'.$schemaName, array(
    'host' => array('','',''),
    'driver'    => 'mongodb',
    'port'     => 27017,
    'database'  => $schemaName,
    'prefix'    => '',
    'options'  => array(
        'replicaSet' => 'replset-name',
        'readPreference' => \MongoClient::RP_SECONDARY_PREFERRED

When I use this, it shows a "No candidate servers found" error. When I use a single host it works well. It will be highly appreciated if you can give a solution to this problem.

  • 1
    Can you add the output of rs.status() and rs.conf from any of the replica set members please? – Adam C Mar 21 '16 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy