php mongoDB aggregate()返回mongoDB\Driver\Cursor对象而不是结果
我正在从mongodb迁移到新的php驱动程序,目前我不知道到底是什么问题,查询与旧驱动程序配合得很好,实际上我没有收到任何查询或php错误。打印返回集合fn的序列,如下所示 php版本:7.1.18, Zend引擎:v3.1.0, mongo:v3.4.15php mongoDB aggregate()返回mongoDB\Driver\Cursor对象而不是结果,php,mongodb,php-7.2,php-mongodb,Php,Mongodb,Php 7.2,Php Mongodb,我正在从mongodb迁移到新的php驱动程序,目前我不知道到底是什么问题,查询与旧驱动程序配合得很好,实际上我没有收到任何查询或php错误。打印返回集合fn的序列,如下所示 php版本:7.1.18, Zend引擎:v3.1.0, mongo:v3.4.15 > MongoDB\Driver\Cursor Object ( > [database] => demoDb > [collection] => > [query] =>
> MongoDB\Driver\Cursor Object (
> [database] => demoDb
> [collection] =>
> [query] =>
> [command] => MongoDB\Driver\Command Object
> (
> [command] => stdClass Object
> (
> [aggregate] => app_button
> [pipeline] => Array
> (
> [0] => stdClass Object
> (
> [$match] => stdClass Object
> (
> [location] => stdClass Object
> (
> [$in] => Array
> (
> [0] => 2978
> [1] => 2979
> [2] => 2980
> [3] => 2981
> [4] => 3060
> [5] => 3061
> [6] => 3062
> [7] => 3063
> [8] => 3064
> [9] => 3065
> [10] => 3066
>
> )
>
> )
>
> [language] => stdClass Object
> (
> [$in] => Array
> (
> [0] => multiselect-all
> [1] => en
> [2] => gr
> [3] => zh
> [4] => vi
> )
>
> )
>
> [$or] => Array
> (
> [0] => stdClass Object
> (
> [hittime] => stdClass Object
> (
> [$regex] => 2018-07-
> )
>
> )
>
> )
>
> )
>
> )
>
> [1] => stdClass Object
> (
> [$group] => stdClass Object
> (
> [_id] => $action
> [count] => stdClass Object
> (
> [$sum] => 1
> )
>
> [totalvalue] => stdClass Object
> (
> [$sum] => $total_value
> )
>
> [optionvalue] => stdClass Object
> (
> [$sum] => $option_value
> )
>
> [recvalue] => stdClass Object
> (
> [$sum] => $rec_value
> )
>
> [data_used] => stdClass Object
> (
> [$sum] => $data_used
> )
>
> )
>
> )
>
> [2] => stdClass Object
> (
> [$sort] => stdClass Object
> (
> [_id] => 1
> )
>
> )
>
> )
>
> [allowDiskUse] =>
> [cursor] => stdClass Object
> (
> )
>
> )
>
> )
>
> [readPreference] => MongoDB\Driver\ReadPreference Object
> (
> [mode] => primary
> )
>
> [session] =>
> [isDead] =>
> [currentIndex] => 0
> [currentDocument] =>
> [server] => MongoDB\Driver\Server Object
> (
> [host] => 127.0.0.1
> [port] => 27017
> [type] => 1
> [is_primary] =>
> [is_secondary] =>
> [is_arbiter] =>
> [is_hidden] =>
> [is_passive] =>
> [last_is_master] => Array
> (
> [ismaster] => 1
> [maxBsonObjectSize] => 16777216
> [maxMessageSizeBytes] => 48000000
> [maxWriteBatchSize] => 1000
> [localTime] => MongoDB\BSON\UTCDateTime Object
> (
> [milliseconds] => 1532060099520
> )
>
> [maxWireVersion] => 5
> [minWireVersion] => 0
> [readOnly] =>
> [ok] => 1
> )
>
> [round_trip_time] => 0
> )
>
> )
代码
aggregate
方法返回一个光标,有关详细信息,请参阅
如果需要将结果用作数组
,可以使用迭代器\u to \u数组
,如下所示:
$resultAsArray = iterator_to_array( $h->aggregate($aggregateArr), false );
现在,$resultAsArray
是一个数组
聚合
方法返回一个光标
,有关详细信息,请参阅
如果需要将结果用作数组
,可以使用迭代器\u to \u数组
,如下所示:
$resultAsArray = iterator_to_array( $h->aggregate($aggregateArr), false );
现在,$resultAsArray
是一个数组
它可以工作了,非常感谢你,你真是一个救命恩人!!。这很有效,非常感谢你,你真是个救命恩人!!。