Add $sampleRate match expression

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Fixed
    • Priority: Major - P3
    • 4.7.0, 4.4.2
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • v4.4
    • Query 2020-06-29
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

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

            Assignee:
            Eric Cox (Inactive)
            Reporter:
            David Percy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: