2

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: 10.0.1.111 is primary replica set, and 10.0.1.112 & 10.0.1.113 is the secondary replica set.

Config::set('database.connections.'.$schemaName, array(
    'host' => array('10.0.1.111','10.0.1.112','10.0.1.113'),
    '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 10.0.1.111 it works well. It will be highly appreciated if you can give a solution to this problem.

migrated from stackoverflow.com Mar 21 '16 at 10:48

This question came from our site for professional and enthusiast programmers.

  • 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