3

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

your answer helped me remove the error 3!=4. However, im now stuck with Pipeline::run(): unrecognized pipeline op "$max . My code looks like : $max_user_no = $collection->aggregate(array(array('$max'=>'user_no'))); . Any clues? Thanks.
I'm having the exact same issue. Is $max/$min not supported?
Max/min are for usage within group, have a look at the docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.