[英]mongo replicaset right connection
I have a problem.Server manager told us to use cluster for mongo settings.He gave to me 3 ip numbers and a replicaset name. 我有一个问题,服务器管理员告诉我们将集群用于mongo设置,他给了我3个IP地址和一个副本集名称。
I wrote a setting like this; 我写了这样的设置;
new MongoDB\Driver\Manager('mongodb://root:password@ip1:27017,ip2:27017,ip3:27017/databaseName?replicaSet=company_mongo);
I have a code like 我有一个类似的代码
<?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>';
}
?>
**I had run this code before, it worked correctly. **我之前已经运行过此代码,它可以正常工作。
But today we are getting the following error.** 但是今天我们遇到了以下错误。**
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] =>
)
Could you help me with the cause of this problem? 您能帮我解决这个问题的原因吗?
It's a ConnectionTimeoutException, there are two things that can go wrong because of which you are seeing the exception: 这是一个ConnectionTimeoutException,有两个地方可能会出错,因此您会看到异常:
w = majority
will never succeed w = majority
将永远不会成功 wtimeout = 100
means 2 out of 3 (one primary and one secondary) servers must apply the writes within 100 ms. wtimeout = 100
表示3个服务器中的2个(一个主服务器和一个辅助服务器)必须在100毫秒内应用写操作。 It is very much possible that writes are already happening on the Primary Mongo Server. 主要Mongo Server上很可能已经在进行写操作。 So, if it's possible, connect to it directly to confirm the same.
因此,如果可能,直接连接到它以确认相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.