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

Add $sampleRate match expression

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

      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@mongodb.com Eric Cox (Inactive)
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: