The MongoCursor object has not been correctly initialized by its constructor
如果你正在構建自己的MongoCursor和覆蓋它的構造函數只應不會發生此錯誤。
這將與例如
class MyCursor extends MongoCursor {
function __construct(MongoClient $connection, $ns , array $query = array(), array $fields = array()) {
/* Do some work, forgetting to call parent::__construct(....); */
}
}
如果您沒有任何擴展類的,那麼這個錯誤是definetly的錯誤發生,你應該report it please :)
How do I guarantee that the MongoClient will connect to at least one of the hosts
至少將將每個數據中心的一個成員放入您的種子列表中。 調整各種超時選項,並計劃主要是關閉的情況下(例如,你應該讀取哪些服務器?)
我懷疑你可能忘了指定「replicaSet」選項,因爲你提到沒有它的連接字符串?
以下片段是我推薦的(隨意調整),特別是當您需要完全一致時(例如始終從主文件讀取)。
<?php
$seedList = "hostname1:port,hostname2:port";
$options = array(
// If the server is down, don't wait forever
"connectTimeoutMS" => 500,
// When the server goes down in the middle of operation, don't wait forever
"socketTimeoutMS" => 5000,
"replicaSet" => "ReplicasetName",
"w" => "majority",
// Don't wait forever for majority write acknowledgment
"wtimeout" => 500,
// When the primary goes down, allow reading from secondaries
"readPreference" => MongoClient::RP_PRIMARY_PREFERRED,
// When the primary is down, prioritize reading from our local datacenter
// If that datacenter is down too, fallback to any server available
"readPreferenceTags" => array("dc:is", ""),
);
try {
$mc = new MongoClient($seedList, $options);
} catch(Exception $e) {
/* I always have some sort of "Skynet"/"Ground control"/"Houston, We have a problem" system to automate taking down (or put into automated maintenance mode) my webservers in case of epic failure.. */
automateMaintenance($e);
}
這不是一個連接問題,這意味着你在你的代碼有錯誤,更具體的,如果它不能連接它會拋出一個異常,說沒有發現候選服務器,當我用我總是得到這個錯誤擴展名錯誤 – Sammaye
所以我做了更多的實驗,並且我認爲我更接近這個問題。我改變連接字符串只指向the_master_node(我刪除the_slave_node),所以現在連接字符串只有一個主機。當奴隸和主人都起來時,它的效果很好。當我取下奴隸時,它開始失敗,有時候給我沒有候選人的錯誤,有時給我一個壞的門戶。要清楚,它是連接字符串中的主,而不是從屬。所以我不明白爲什麼取下奴隸會導致這樣的級聯錯誤。有任何想法嗎? –
嗯這是什麼驅動程序版本?還有什麼是你的閱讀偏好? – Sammaye