<?php
$m = new \MongoDB\Client();
$res = $m->tutorial->beer->aggregate( [
[ '$match' => [ 'venue_name' => [ '$ne' => null ] ] ],
[ '$group' => [ '_id' => [ 'venue' => '$venue_name', 'beer' => '$beer_name' ] ] ],
[ '$group' => [ '_id' => '$_id.venue', count => [ '$sum' => 1 ] ] ],
[ '$sort' => [ 'count' => -1 ] ],
[ '$limit' => 5 ],
] );
foreach ( $res as $result )
{
echo $result['_id'], ': ', $result['count'], "\n";
}
?>