I'm attempting to use the new mongodb aggregation framework from php.
I'm using mongod v2.2, php 5.3.13, and mongodb pecl library v1.3.0beta2 on OSX Mountain Lion
I'm stumbling right at the gates...
I've taken one of the examples from the php docs page and cut it down to...
$m = new Mongo;
$c = $m->selectDB("test")->selectCollection("zips");
$out = $c->aggregate(array('$group' => array('_id' => '$state')));
var_dump($out);
When I view the page I get an error on my mongod of...
Assertion 13111: :wrong type for field (pipeline) 3 != 4
I can't for the life of me see anything wrong with the code.
if I run db.zips.aggregate({$group : {'_id': "$state"}}) in the mongo console it works fine.
This might sound stupid, and I know the MongoCollection::aggregate docs say that the method accepts multiple arguments as steps to the pipeline, but the only way I have managed to make this work is by issuing a single argument that contains all of the pipeline steps, like so:
$out = $c->aggregate(array(
array(
'$group' => array('_id' => '$state')
)
);
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With