Groupe par le comte Mongodb Laravel
<?php
$category_ids = []; //categories goes here
$results = Post::raw(function($collection) use ($category_ids) {
return $collection->aggregate([
//where in...
[
'$match' => [
'category_id' => ['$in' => $category_ids]
]
],
[
'$group' => [
'_id' => '$user_id',
'count' => ['$sum' => 1]
]
],
[
'$sort' => ['count' => -1]
],
[
'$limit' => 10
],
]);
});
company MO