我在使用PHP腳本嘗試瀏覽我的一個集合中的所有文檔時遇到問題。該集合有大約500k個文檔。數據庫正在運行在Ubuntu 14.04上運行的Mongo 2.6.9。我使用這個語法搜索collecton:文檔長度不等於緩衝區
$mongo = new MongoClient("mongodb://192.168.2.2:27017,192.168.2.3:27017/products?replicaSet=preplset");
$products = $mongo->products->content;
$cursor = $products->find();
while($cursor->hasNext() !== false) {
echo "some information";
}
我收到以下錯誤消息(堆轉儲):
object(MongoCursorException)#24 (8) {
["message":protected]=> string(61) "Document length (74 bytes) is not equal to buffer (219 bytes)"
["string":"Exception":private]=> string(0) ""
["code":protected]=> int(42)
["file":protected]=> string(41) "...script.php"
["line":protected]=> int(29)
["trace":"Exception":private]=>
array(1) {
[0]=> array(6) {
["file"]=> string(41) "...value.php"
["line"]=> int(29)
["function"]=> string(7) "getNext"
["class"]=> string(11) "MongoCursor"
["type"]=> string(2) "->"
["args"]=> array(0) {}
}
}
["previous":"Exception":private]=> NULL
["host":"MongoCursorException":private]=> NULL
}
長度變化。我看到了十幾種不同的長度。每次運行此腳本時,它都會獲得不同百分比的集合。有時它會在4k文件之後拋出這個異常,有時候是180k。我確定我在任何時候都對系列進行了更改,它是一個正在不斷更新的生產數據庫
對於臨時性的問題,我很高興看到一種方法來捕獲異常並處理它。我有一個try/catch塊,但這個異常導致我的腳本退出。 – JohnGalt