我在php中循环查询的mongodb游标以弹性索引文档。
当我在游标循环中随机出现以下错误时,索引过程中断:
======================================================================
The application has thrown an exception!
======================================================================
MongoDB\Driver\Exception\UnexpectedValueException
Could not convert BSON document to a PHP variable
----------------------------------------------------------------------
它发生在这一行:
foreach ($webpageCursor as $id => $webpage) {...
我甚至无法输出可能无效的对象,因此我不知道是哪一个造成它。
有没有办法避免这个问题?
编辑:
这里是游标创建代码:
/**
* Get webpages
*
* @param string $database The database name
* @param int $limit The limit for the query
* @return \MongoCursor
*/
public function getDocumentsCursor($database, $limit = null)
{
$mongoClient = $this->getMongoDbService()->getMongoDbClient();
$collection = $mongoClient->selectCollection($database, 'documents');
return $collection->find(
[
'text' => [
'$exists' => true
],
'parsed' => [
'$ne' => new \MongoDB\BSON\UTCDateTime(-62135596800000),
],
'fetched' => [
'$ne' => new \MongoDB\BSON\UTCDateTime(-62135596800000),
],
'pointsToCanoncial' => [
'$ne' => true
],
'noIndex' => [
'$ne' => true
],
'lastStatusCode' => [
'$gte' => 200,
'$lt' => 300
]
],
[
'noCursorTimeout' => true,
'projection' => [
'_id' => true,
'meta' => true,
'url' => true,
'text' => true,
'contentType', true,
'header' => true,
'inlinks' => true,
],
'limit' => $limit,
]
);
}