I'm not trying to limit the number of results. I'm trying to find a way to only cycle N documents of the collection, when using
collection->find([]);
Is there an option or flag for that? Using PHP Cheers.
CodePudding user response:
Maybe $sample is what you are looking for.
It will randomly select N documents from the collection:
db.collection.aggregate([
{ $sample: { size: 10 } }
])