错误信息:
PHP Fatal error: Uncaught MongoDB\\Driver\\Exception\\RuntimeException: Invalid reply to find command. in .../library/MongoDB/Operation/Find.php:299
Stack trace:
#0 .../library/MongoDB/Operation/Find.php(299): MongoDB\\Driver\\Server->executeQuery('crm.t_accountin...', Object(MongoDB\\Driver\\Query), Array)
#1 .../library/MongoDB/Operation/FindOne.php(126): MongoDB\\Operation\\Find->execute(Object(MongoDB\\Driver\\Server))
#2 .../library/MongoDB/Collection.php(657): MongoDB\\Operation\\FindOne->execute(Object(MongoDB\\Driver\\Server))
#3 .../Mongo.php(211): MongoDB\\Collection->findOne(Array, Array)
#4 xxx.php(315): xxx->fetchRow('xxx...', Array, 'xxx...')
#5 xxx.php(220): xxx->fetchR in xxx/library/MongoDB/Operation/Find.php on line 299
网上有些说这个问题在 1.2 版本中已经修复了:
PHPC-625
mongodb/mongo-php-driver#174
mongodb/mongo-php-driver#527
语法是根据 php-library findOne文档 来的
自己操作类中的 fetchRow
,其中私有函数都是些简单的转换:
/**
* 返回一行数据
*
* @param string $collectionName 集合名
* @param array $condition 条件
* @param string|null $fields 字段
* @return array|bool
*/
public function fetchRow($collectionName, $condition = [], $fields = null) {
$options = [];
if (! empty($fields)) {
$options['projection'] = $this->_toFieldsArray($fields);
}
$result = $this->getConnection()
->selectCollection($this->database, $collectionName)
->findOne($condition, $options);
$result = $this->_toArray($result);
return $this->_checkCharset($result, false);
}
MongoDB版本
3.2.0
MongoDB extension version
1.5.1 stable
If you have reproducible errors on the most recent stable release of the driver (1.5.x), please open a new issue so we can investigate and track that going forward. I'm not sure why you would be calling
pcntl_fork()
from a web SAPI, but note that the driver still does not support sharing its resources across forked PHP processes. The fixes I referred to in #174 (comment) only pertain to including the PID when persisting libmongoc client objects (and their sockets), which ensure that creating a new Manager in a child process with the same URI will not attempt to re-use resources from the parent process.