Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

9. Stages at a glance

The 28 built-in stages, in catalogue order. .query.stages lists the same catalogue from a running node.

StageAliasesFamilySummaryFlowRows
whereFilteringKeeps the rows whose predicate is truestreamingfewer
selectprojectShapingKeeps the listed fields and named expressionsstreamingsame
deriveShapingAdds or replaces computed fieldsstreamingsame
renameShapingRenames one fieldstreamingsame
dropShapingRemoves fieldsstreamingsame
rootShapingReplaces each row by one of its object fieldsstreamingsame
nearVectorScores rows by vector similaritystreamingfewer
sortOrderingOrders rows by keysblockingsame
limitPagingKeeps the first n rowsstreamingfewer
skipoffsetPagingDrops the first n rowsstreamingfewer
firstPagingKeeps the first rowstreamingfewer
singlePagingRequires exactly one rowstreamingfewer
sampleSamplingKeeps n rows drawn uniformlyblockingfewer
unwindArraysEmits one row per array itemstreamingmore
distinctDeduplicationKeeps one row per distinct keyblockingfewer
countCountingReturns the number of rowsstreamingone, terminal
groupAggregationAggregates rows by keysblockingfewer
bucketAggregationCounts rows per value rangeblockingfewer
fillAnalyticsAdds the rows a grid of values misses in each partitionblockingmore
windowAnalyticsAdds values over ordered partitionsblockingsame
pivotAggregationCross-tabulates rows by row and column keysblockingone per row key
lookupjoinCombiningAttaches the matching rows of another collectionblockingsame
unionCombiningAppends the rows of another pipelineblockingmore
insertWriteInserts documentstransactionalonly stage
setWriteUpdates fields of the matching documentstransactionalterminal
deleteWriteDeletes the matching documentstransactionalterminal
intooutWriteWrites the rows into a collectiontransactionalterminal
loadWriteImports or upserts documentstransactionalfirst, terminal

Flow. Streaming stages handle one row at a time. Blocking stages need their whole input first (they spill to disk when it outgrows memory, chapter 14). Transactional stages write.

Choosing a stage

I want to…Use
keep some rowswhere
keep some fieldsselect, or drop the others
add a computed fieldderive
rename a fieldrename, or select old as new
promote a sub-objectroot
order rowssort
take the top Nsort … | limit N
pageskip k | limit n
get one row, or failsingle
one row per array itemunwind
distinct valuesselect f | distinct, or distinct f
count rowscount, or group f per value
totals per keygroup
histogramsbucket
a cross tablepivot
previous / next row, running totals, rankswindow
complete missing monthsfill
attach related rowslookup
stack two sourcesunion
copy results into a collectioninto
bulk import, upsertload
nearest vectorsnear | sort _distance | limit k

Entry layout

Every entry reads: Definition, Syntax, Behavior, Examples, Errors and limits, See also.