【发布时间】:2016-02-19 21:57:26
【问题描述】:
我在尝试使用 PHP 脚本浏览我的一个集合中的所有文档时遇到了问题。该集合有大约 500k 个文档。该数据库运行 Mongo 2.6.9,在 Ubuntu 14.04 上运行。我正在使用这种语法来搜索集合:
$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 块中有它,但是这个异常会导致我的脚本退出。
标签: php mongodb buffer document