php - 命令光标未返回结构正确的响应
问题描述
我将我的 mongo 从 2.6 更新到 4。我遇到了聚合查询的问题。我收到消息:the command cursor did not return a correctly structured response
。
正如在此 anwser中所读,我将配置用于
ini_set('mongo.native_long', false);
ini_set('mongo.long_as_object', true);
但现在我得到了错误Notice: Object of class MongoInt64 could not be converted to int
。
有人知道如何解决这个问题吗?
的结果php --ri mongodb
php --ri mongodb
mongodb
MongoDB support => enabled
MongoDB extension version => 1.5.5
MongoDB extension stability => stable
libbson bundled version => 1.13.0
libmongoc bundled version => 1.13.0
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => disabled
libmongoc ICU => disabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
Directive => Local Value => Master Value
mongodb.debug => no value => no value
抛出异常的代码
$queryBuilder = $this->createQueryBuilder();
return $this->createAggregationBuilder()->match()
->field('delivery')->references($delivery)
->field('dateDeleted')->equals(null)$aggregation
->group()
->field('id')
->expression(null)
->field('count')
->sum(1)->execute()->getSingleResult();
解决方案
通过添加ini_options
它可以解决the command cursor did not return a correctly structured response
. 但是由于某些数据已经存在于数据库中,这些数据是由旧版 Mongo 驱动程序创建的,因此无法获取数据。
因此,我需要删除所有文档以使用干净的数据库重新启动。