How can I resolve following error on Yii collection aggregate:
“each item in the pipeline must be a document”
with this code:
$collection = Yii::$app->mongodb->getCollection('lc_executive_allocate');
$asCursor = true;
$result = $collection->aggregate([
[
'$match' => [
'stage' => '2',
'completed' => '1',
'status' => '1',
'assignedOn' => ['$gte' => '2018-03-01', '$lte' => '2018-03-29'],
],
],
[
'$group' => [
'_id' => ['userId' => '$userId', 'count' => ['$sum' => '1']],
],
],
['$sort' => ['count' => '-1']],
['$limit' => '1'],
$asCursor,
]);