This match expression takes a floating point number between 0 and 1 (both inclusive) with 0 matching nothing and 1 matching all. It desugars to {$expr: {$rand: ...}}
Unlike $sample, which is an experession, $sampleRate is a match-expression, which can go inside .find() or {$match: _}.
For example, the pipeline:
{$match: {$sampleRate: 0.25}}
Would select on average 1/4 of the input documents. It could desugar to
{$match: {$expr: {$lt: [ {$rand: {}}, 0.25 ]}}}
- depends on
-
SERVER-30405 add expression to generate a random number
- Closed