[DOCS-14855] Reword $sample documentation on how $sample behaves Created: 07/Oct/21  Updated: 13/Nov/23  Resolved: 18/Oct/21

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: 4.0.0, 4.2.0, 4.4.0, 5.0.0, 5.1.0, Server_Docs_20231030, Server_Docs_20231106, Server_Docs_20231105, Server_Docs_20231113

Type: Task Priority: Minor - P4
Reporter: Emre Ucal Assignee: Jason Price
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 2 years, 16 weeks, 2 days ago
Epic Link: DOCSP-11701
Story Points: 3

 Description   

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"



 Comments   
Comment by Githook User [ 18/Oct/21 ]

Author:

{'name': 'jason-price-mongodb', 'email': '69260375+jason-price-mongodb@users.noreply.github.com', 'username': 'jason-price-mongodb'}

Message: DOCS-14855 reword-sample (#6012) (#6016)

Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>

Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>
Branch: v4.0
https://github.com/mongodb/docs/commit/73e08fd865fe3948784cf08d35513c9750c415a1

Comment by Githook User [ 18/Oct/21 ]

Author:

{'name': 'jason-price-mongodb', 'email': '69260375+jason-price-mongodb@users.noreply.github.com', 'username': 'jason-price-mongodb'}

Message: DOCS-14855 reword-sample (#6012) (#6015)

Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>

Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>
Branch: v4.2
https://github.com/mongodb/docs/commit/f0f0029acbb2b2adf4681a32c0b54fa1e3bfebdf

Comment by Githook User [ 18/Oct/21 ]

Author:

{'name': 'jason-price-mongodb', 'email': '69260375+jason-price-mongodb@users.noreply.github.com', 'username': 'jason-price-mongodb'}

Message: DOCS-14855 reword-sample (#6012) (#6014)

Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>

Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>
Branch: v4.4
https://github.com/mongodb/docs/commit/80548c9180a652abed3a21e674e2951d0928b285

Comment by Githook User [ 18/Oct/21 ]

Author:

{'name': 'jason-price-mongodb', 'email': '69260375+jason-price-mongodb@users.noreply.github.com', 'username': 'jason-price-mongodb'}

Message: DOCS-14855 reword-sample (#6012) (#6013)

Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>

Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>
Branch: v5.0
https://github.com/mongodb/docs/commit/f60846a60ae1139cfd342ca52695b8744db1a346

Comment by Githook User [ 18/Oct/21 ]

Author:

{'name': 'jason-price-mongodb', 'email': '69260375+jason-price-mongodb@users.noreply.github.com', 'username': 'jason-price-mongodb'}

Message: DOCS-14855 reword-sample (#6012)

Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>
Branch: master
https://github.com/mongodb/docs/commit/f804a406715324b8d6d1ebb59e185d4f4c2bc178

Generated at Thu Feb 08 08:11:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.