1

使用ichikaway-cakephp我正在尝试将以下查询(在 php 中运行良好)转换为 cakephp

在 cakephp 它返回空数组

核心 PHP

  $out = $collection->aggregate(array(
     array('$unwind' => '$as'),
     array(
        '$group' => array(
            '_id' => array('as'=>'$as'),
           'count' => array('$sum' => 1)
        )
    )
));

Cakephp

$conditions=array('aggregate'=>array(
                            array('$unwind' => '$as'),
                            array(
                                '$group' => array(
                                    '_id' => array('as'=>'$as'),
                                   'count' => array('$sum' => 1)
                                )
                            )
                            ));

$results = $this->Post->find('all',array('conditions'=>$conditions));

我无法在测试用例中找到聚合框架功能

到目前为止,只有这个提交谈论聚合。

4

1 回答 1

0
$params = array(
    array('$unwind' => '$as'),
        array(
            '$group' => array(
                '_id' => array('as'=>'$as'),
                'count' => array('$sum' => 1)
             )
        )
));

$mongo = $this->Post->getDataSource();
$mongoCollectionObject = $mongo->getMongoCollection($this->Post);


$results = $mongoCollectionObject->aggregate($params);
于 2014-07-27T14:53:37.507 回答