Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It throws error when using mongodb aggregate #278

Open
wangking717 opened this issue Jun 17, 2019 · 5 comments
Open

It throws error when using mongodb aggregate #278

wangking717 opened this issue Jun 17, 2019 · 5 comments
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug

Comments

@wangking717
Copy link

wangking717 commented Jun 17, 2019

via mongodb version 4.0.3

when using mongodb aggregate ,it throws error.

$pipeline = [
            ['$group' => [
                '_id' => null,
                'count' => [
                    '$sum' => 1
                ],
            ]],
];

$stat_data = CustomerOrder::getCollection()->aggregate($pipeline);
var_dump($stat_data);

Error info:

The 'cursor' option is required, except for aggregate with the explain argument

@samdark samdark added status:to be verified Needs to be reproduced and validated. type:bug Bug labels Jun 18, 2019
@wangking717
Copy link
Author

when using
$num = CustomerOrder::find()->count(); // sum() also...
it throws the error too.. using mongodb 4.0.3

Error info:

The 'cursor' option is required, except for aggregate with the explain argument

@samdark samdark added status:ready for adoption Feel free to implement this issue. and removed status:to be verified Needs to be reproduced and validated. labels Jun 27, 2019
@rustamwin
Copy link
Member

rustamwin commented Jul 23, 2019

Which is version your yii2-mongodb ?

@wangking717
Copy link
Author

"yiisoft/yii2-mongodb": "~2.1.0"

Which version your yii2-mongodb ?

@rustamwin
Copy link
Member

I think you have to use $match pipeline stage

$pipeline = [
            ['$match' => [
                //
            ]
            ['$group' => [
                '_id' => null,
                'count' => [
                    '$sum' => 1
                ],
            ]],
];

@wangking717
Copy link
Author

I think you have to use $match pipeline stage

$pipeline = [
            ['$match' => [
                //
            ]
            ['$group' => [
                '_id' => null,
                'count' => [
                    '$sum' => 1
                ],
            ]],
];

I didn't use $match pipeline stage.

when using this issue, it throws error too.
$num = CustomerOrder::find()->count(); // sum() also...
it throws the error too.. using mongodb 4.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants