Skip to content

Added support for MongoDB aggregation framework to the datasource - #74

Open
codingthoughts wants to merge 2 commits into
ichikaway:cake2.2from
codingthoughts:cake2.2
Open

Added support for MongoDB aggregation framework to the datasource#74
codingthoughts wants to merge 2 commits into
ichikaway:cake2.2from
codingthoughts:cake2.2

Conversation

@codingthoughts

Copy link
Copy Markdown

Now, we can pass something like:

$conditions = array(
'aggregate' => array(
array(
'$match' => array(
'refNo' => 1,
'date' => array(
'$gte' => '2013-03-30',
'$lte' => '2013-04-30'
)
)
),
array(
'$group' => array(
'_id' => '$product',
'count' => array(
'$sum' => '$count'
)
)
),
array(
'$project' => array(
'product' => '$_id',
'count' => 1
)
)
)
)

to the paginate or find method. It is the same array as you would pass to the MongoDB aggregate method for the PHP driver.

Fully works with pagination.

@k1LoW

k1LoW commented May 1, 2013

Copy link
Copy Markdown
Contributor

If you can, add testcase, because I do not know what is correct.

@codingthoughts

Copy link
Copy Markdown
Author

Sure, i will add test cases and commit them soon.

@k1LoW

k1LoW commented May 1, 2013

Copy link
Copy Markdown
Contributor

Thank you !

@codingthoughts

Copy link
Copy Markdown
Author

Hi, I have added test cases.

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 0303bac on codingthoughts:cake2.2 into * on ichikaway:cake2.2*.

@k1LoW

k1LoW commented May 2, 2013

Copy link
Copy Markdown
Contributor

Unfortunately, testcase failed in Travis CI. (maybe mongo version)

check following url
https://travis-ci.org/ichikaway/cakephp-mongodb/builds/6792448

@codingthoughts

Copy link
Copy Markdown
Author

Hi, I looked at it. The case is failing in PECL Mongo 1.2.9 driver which is almost a year old and it did not have the support for aggregation framework. All the newer versions support aggregation.Aggregation requires version greater than 1.3.0.

Checkout:
http://pecl.php.net/package/mongo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants