$sample

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: Pipeline stages

What it does

Selects a sample of documents.

Syntax

{$sample: { size: n }}

Use case

Exploratory sampling and test fixtures.

$sample: practical example
{ $sample: { size: 100 } }
💡 Explanation Selects a sample of documents. When to use it Exploratory sampling and test fixtures.
Key Takeaways
  • Selects a sample of documents.
  • Typical use: Exploratory sampling and test fixtures.