Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-14855

Reword $sample documentation on how $sample behaves

      The $sample  documentation https://docs.mongodb.com/manual/reference/operator/aggregation/sample/#behavior states the following:
      “If all the following conditions are met, $sample uses a pseudo-random cursor to select documents: * $sample is the first stage of the pipeline

      • N is less than 5% of the total documents in the collection
      • The collection contains more than 100 documents

      If any of the above conditions are NOT met, $sample performs a collection scan followed by a random sort to select N documents.

      That to me sounds like if $sample comes in second stage it will perform a collection scan (not saying it actually does a collection scan, but the bold sentence make it sound like it would). 
       
      The bold sentence above can be changed to:
      "If any of the above conditions are NOT met, $sample will process all input documents (that come from either a preceding aggregation stage or a collection scan) followed by a random sort to select N documents"

            Assignee:
            jason.price@mongodb.com Jason Price
            Reporter:
            emre.ucal@mongodb.com Emre Ucal
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              2 years, 40 weeks, 4 days ago