I have a MongoDB 2.2 replicaset setup (2 nodes), and connect to test using PHP, e.g.
$mongo = new Mongo("mongodb://192.168.1.1:27017,192.168.1.2:27017",
array("replicaSet" => "testrs",
"safe" => TRUE));
$db = $mongo->test;
$collection = $db->dump;
while (true) {
echo "Result: " .
$collection->insert(array( "ts" => time() ));
sleep(10);
}
During the middle of the execution, when I stepDown from the primary node, I found the insert stop working but the echo stil give me 1, so no exception was throw, any issue with my code above?
As you can read here,
insertthrows exceptions only whensafeoption is set:Set
safeoption and you should be able to see the exception thrown.