[SERVER-48474] Add $sampleRate match expression Created: 28/May/20  Updated: 29/Oct/23  Resolved: 25/Jun/20

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.7.0, 4.4.2

Type: New Feature Priority: Major - P3
Reporter: David Percy Assignee: Eric Cox (Inactive)
Resolution: Fixed Votes: 0
Labels: qopt-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
depends on SERVER-30405 add expression to generate a random n... Closed
Documented
is documented by DOCS-13885 Investigate changes in SERVER-48474: ... Closed
Backwards Compatibility: Fully Compatible
Backport Requested:
v4.4
Sprint: Query 2020-06-29
Participants:

 Description   

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 ]}}}



 Comments   
Comment by Githook User [ 11/Sep/20 ]

Author:

{'name': 'Eric Cox', 'email': 'eric.cox@mongodb.com', 'username': 'ericox'}

Message: SERVER-48474 add '$sampleRate' match expression
Branch: v4.4
https://github.com/mongodb/mongo/commit/4eed32988c1282787787371475870c0b47967784

Comment by Githook User [ 25/Jun/20 ]

Author:

{'name': 'Eric Cox', 'email': 'eric.cox@mongodb.com', 'username': 'ericox'}

Message: SERVER-48474 add '$sampleRate' match expression
Branch: master
https://github.com/mongodb/mongo/commit/a823c69a5dec5e8705bc754038f914e0784d8d09

Comment by Eric Cox (Inactive) [ 24/Jun/20 ]

Code Review: https://mongodbcr.appspot.com/595350002/

Generated at Thu Feb 08 05:17:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.