Is MongoDB capable of funding number of random documents without making multiple queries?
e.g. I implemented on the JS side after loading all the document in the col
Since 3.2 there is an easier way to to get a random sample of documents from a collection:
$sample New in version 3.2.
Randomly selects the specified number of documents from its input.
The $sample stage has the following syntax:
{ $sample: { size:} }
Source: MongoDB Docs
In this case:
db.products.aggregate([{$sample: {size: 10}}]);