我有一个问题。服务器管理员告诉我们使用群集进行mongo设置。他给了我3个ip号码和一个replicaset名字。
我写了这样的设置;
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] =>
)
你能帮我解决这个问题的原因吗?
答案 0 :(得分:0)
这是一个ConnectionTimeoutException,有两件事可能会出错,因为你看到了异常:
w = majority
将永远不会成功wtimeout = 100
表示2个中的2个(一个主服务器和一个辅助服务器)必须在100毫秒内应用写入。很可能在主Mongo服务器上已经发生了写入。因此,如果可能的话,直接连接到它以确认相同。