Skip to content

docs: expand sample() example to show sampling from a filtered subset#16369

Merged
vkarpov15 merged 1 commit into
Automattic:masterfrom
Wnayar:docs/random-document-sampling
Jul 8, 2026
Merged

docs: expand sample() example to show sampling from a filtered subset#16369
vkarpov15 merged 1 commit into
Automattic:masterfrom
Wnayar:docs/random-document-sampling

Conversation

@Wnayar

@Wnayar Wnayar commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

The Aggregate#sample() docs currently show only a single example sampling from the whole collection. This adds a second example demonstrating .match().sample(), which samples from a filtered subset rather than the whole collection. This is a common use case, and the stage ordering (filter before sample) is worth showing explicitly.

Examples

// picks 3 random documents from the whole collection
aggregate.sample(3);

// `$match` before `$sample` samples from the filtered subset
aggregate.match({ difficulty: 'easy' }).sample(3);

@vkarpov15 vkarpov15 added this to the 9.8 milestone Jul 8, 2026
@vkarpov15 vkarpov15 merged commit 3a8b47e into Automattic:master Jul 8, 2026
26 checks passed
@Wnayar Wnayar deleted the docs/random-document-sampling branch July 8, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants