laravel mongodbでグルーピングしたキーでソート mongodb
mongodbでグルーピングしたキーでソート(larabel使用時)
<br>
以下、hostnameでグルーピングしている場合、その名前でソート。逆の場合(desc)は、-1にする
<br>
<pre class= brush:php >
$posts2 = Post::raw(function ($collection) {
return $collection->aggregate([
[
     $match  => [
         rtype    =>  rtype_2 
    ]
] 
[
     $group  => [
         _id    => [
             hostname  =>  $hostname 
        ] 
         count  => [
             $sum  => 1
        ]
    ]
] 
[ 
     $sort  => [
         _id  => 1 
    ]
]
]);
});
</pre>