new MongoDB\Driver\Manager('mongodb://root:password@ip1:27017,ip2:27017,ip3:27017/databaseName?replicaSet=company_mongo);
我有一个类似的代码
<?php
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(['_id' => 3333333]);
$manager = new MongoDB\Driver\Manager('mongodb://root:pass@ip1:27017,ip2:27017,ip3:27017/databaseName?replicaSet=company_mongo);
$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 100);
try {
$result = $manager->executeBulkWrite('test.foo', $bulk, $writeConcern);
}
catch(\Exception $e){
echo '<pre>';
print_r($e);
echo '</pre>';
}
?>
今天我们会遇到以下错误。**
MongoDB\Driver\Exception\ConnectionTimeoutException Object
(
[message:protected] =>
[string:Exception:private] =>
[code:protected] => 13053
[file:protected] => /../mongotest.php
[line:protected] => 22
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /../mongotest.php
[line] => 22
[function] => executeBulkWrite
[class] => MongoDB\Driver\Manager
[type] => ->
[args] => Array
(
[0] => test.foo
[1] => MongoDB\Driver\BulkWrite Object
(
[database] =>
[collection] =>
[ordered] => 1
[bypassDocumentValidation] =>
[executed] =>
[server_id] => 0
[write_concern] =>
)
[2] => MongoDB\Driver\WriteConcern Object
(
[w] => majority
[wtimeout] => 100
)
)
)
)
[previous:Exception:private] =>
)
你应该帮助我解决这个问题吗?
是A
ConnectionTimeoutException
,这是由两件事可能出错的事情引起的:
w = majority
指3分(一个主要和一个次级服务器中的2个)必须在100ms.
之内使用书面。很有可能在主Mongo服务器上已经进行了写作。因此,如果可能的话,直接连接到它以确认相同。