環境:
Laravel@9.52.4
jenssegers/laravel-mongodb@3.9.5
$Posts = Post::raw(function($collection) {
return $collection->aggregate([
['$sample' => ['size' => 5]],
['$project' => ['title' => 1, 'body' => 1]]
]);
});
ref:
/* Get Random Order Items from MongoDB Collection */