sample

open fun sample(size: Int): Pipeline<Document>(source)

Randomly selects size documents.

Pipeline optimizations

MongoDB is able to perform sampling more efficiently if it is the first stage of the pipeline and size is less than 5% of the collection size.

External resources

See also

Selects the first elements found.