burger
burger

Reputation: 5883

How can I confirm PHP MongoDB connection is properly recognizing replica sets?

Using the example from the manual:

$mongo = new Mongo("mongodb://sf2.example.com,ny1.example.com", array("replicaSet" => "myReplSet"));

When I check $mongo, it says it is indeed connected. I thought I could then call $mongo->isMaster() to get replica set details, but that doesn't work. Is that not a proper way of doing this?

Upvotes: 0

Views: 498

Answers (1)

kris
kris

Reputation: 23591

isMaster isn't a PHP function (see http://www.php.net/manual/en/class.mongo.php for a list of functions available in the Mongo class). You can do:

$result = $mongo->myDb->command(array("isMaster" => 1));

This runs the isMaster command on the myDb database (it doesn't matter what db you run it on).

Upvotes: 4

Related Questions