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

Add $sampleRate match expression

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 4.7.0, 4.4.2
    • None
    • Fully Compatible
    • v4.4
    • Query 2020-06-29

    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

              eric.cox@mongodb.com Eric Cox (Inactive)
              david.percy@mongodb.com David Percy
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: