yiisoft / yii2-mongodb

Yii 2 MongoDB extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
326 stars 191 forks source link

Group or Group By support is not available for mongodb yii2 #335

Closed Vatsal-Innovatemr closed 3 years ago

Vatsal-Innovatemr commented 3 years ago

I am not able to use group or groupBy in active data provider using yii2-MongoDB. Can anyone help me with the same?

Q A
Yii version 2.1
Yii MongoDB version 2.1.11
MongoDB server version 4.2
PHP version 7.1
Operating system ubuntu 18.04
bizley commented 3 years ago

Do you mean that the aggregation pipeline does not work?

yii-bot commented 3 years ago

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

Vatsal-Innovatemr commented 3 years ago

Do you mean that the aggregation pipeline does not work?

I am using find() as below, $query = User::find(); $query->select(['id','_id','email','status']); $query->group('email');

Gives me the below error, { "name": "Exception", "message": "Calling unknown method: yii\mongodb\ActiveQuery::group()", "code": 0, "type": "yii\base\UnknownMethodException", "file": "C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\Component.php", "line": 301, "stack-trace": [ "#0 C:\xampp\htdocs\panels\common\models\panelist\PanelistGetCountV5.php(263): yii\base\Component->__call('group', Array)", "#1 C:\xampp\htdocs\panels\api\modules\v1\controllers\PanelistController.php(1664): common\models\panelist\PanelistGetCountV5->searchQualified(Array)", "#2 [internal function]: api\modules\v1\controllers\PanelistController->actionGetCount()", "#3 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)", "#4 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\Controller.php(181): yii\base\InlineAction->runWithParams(Array)", "#5 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\Module.php(534): yii\base\Controller->runAction('get-count', Array)", "#6 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\web\Application.php(104): yii\base\Module->runAction('v1/panelist/get...', Array)", "#7 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\Application.php(392): yii\web\Application->handleRequest(Object(yii\web\Request))", "#8 C:\xampp\htdocs\panels\api\web\index.php(49): yii\base\Application->run()", "#9 {main}" ] }

Same for groupBy as well, { "name": "Exception", "message": "Calling unknown method: yii\mongodb\ActiveQuery::groupBy()", "code": 0, "type": "yii\base\UnknownMethodException", "file": "C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\Component.php", "line": 301, "stack-trace": [ "#0 C:\xampp\htdocs\panels\common\models\panelist\PanelistGetCountV5.php(263): yii\base\Component->__call('groupBy', Array)", "#1 C:\xampp\htdocs\panels\api\modules\v1\controllers\PanelistController.php(1664): common\models\panelist\PanelistGetCountV5->searchQualified(Array)", "#2 [internal function]: api\modules\v1\controllers\PanelistController->actionGetCount()", "#3 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)", "#4 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\Controller.php(181): yii\base\InlineAction->runWithParams(Array)", "#5 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\Module.php(534): yii\base\Controller->runAction('get-count', Array)", "#6 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\web\Application.php(104): yii\base\Module->runAction('v1/panelist/get...', Array)", "#7 C:\xampp\htdocs\panels\vendor\yiisoft\yii2\base\Application.php(392): yii\web\Application->handleRequest(Object(yii\web\Request))", "#8 C:\xampp\htdocs\panels\api\web\index.php(49): yii\base\Application->run()", "#9 {main}" ] }

Vatsal-Innovatemr commented 3 years ago

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

Provided information here https://github.com/yiisoft/yii2-mongodb/issues/335#issuecomment-858664286

bizley commented 3 years ago

There is no group() method in MongoDB Yii package. You must use the aggregation methods like in the linked documentation.

Vatsal-Innovatemr commented 3 years ago

There is no group() method in MongoDB Yii package. You must use the aggregation methods like in the linked documentation. Yes, I know the alternate. But is there any scope of improvement to add these features?

bizley commented 3 years ago

Not that I know of.

Vatsal-Innovatemr commented 3 years ago

Not that I know of.

Okay 👍