Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-48474

Add $sampleRate match expression

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.7.0, 4.4.2
    • Component/s: None
    • Labels:

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              eric.cox Eric Cox
              Reporter:
              david.percy David Percy
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: