我在使用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