$sampleRate
Randomly selects documents from the input at the specified rate, useful for sampling large datasets or creating representative subsets for analysis.
Syntax
{ $sampleRate: <rate> }
Parameters
rate
numberrequiredThe sample rate as a number between 0 and 1, representing the percentage of documents to select
Examples
Sample 10% of documents
Randomly select 10% of documents from a collection
Query:
db.products.aggregate([{ $sampleRate: 0.1 }])
Output:
Approximately 10% of the documents from the products collection