-
Notifications
You must be signed in to change notification settings - Fork 0
Aggregation Pipeline
The following 34 aggregation pipeline stages are supported:
| Stage | Description |
|---|---|
$match |
Filter documents |
$project |
Reshape documents (include, exclude, compute fields) |
$addFields / $set
|
Add or overwrite fields |
$unset |
Remove fields |
$group |
Group by key with accumulators |
$sort |
Sort documents |
$limit |
Limit number of documents |
$skip |
Skip documents |
$unwind |
Deconstruct array field |
$lookup |
Left outer join to another collection |
$replaceRoot / $replaceWith
|
Replace document with a sub-document |
$count |
Count documents |
$sortByCount |
Group, count, and sort |
$sample |
Random sample |
$facet |
Multiple sub-pipelines in parallel |
$bucket |
Categorize into buckets |
$bucketAuto |
Auto-bucket by count |
$unionWith |
Union with another collection |
$graphLookup |
Recursive graph lookup |
$redact |
Restrict document content |
$merge |
Write results to a collection |
$out |
Write results to a collection (replace) |
$setWindowFields |
Window functions |
$densify |
Fill gaps in sequence |
$fill |
Fill missing values |
$documents |
Provide literal documents |
$collStats |
Collection statistics |
$indexStats |
Index statistics |
$geoNear |
Geospatial near query |
$search |
Atlas text search (basic substring support) |
$searchMeta |
Atlas search metadata (stub) |
$vectorSearch |
Vector similarity search (brute-force) |
| Accumulator | Description |
|---|---|
$sum |
Sum of values |
$avg |
Average of values |
$min |
Minimum value |
$max |
Maximum value |
$first |
First value in group |
$last |
Last value in group |
$push |
Array of all values |
$addToSet |
Array of unique values |
$count |
Count of documents |
$mergeObjects |
Merge documents |
$stdDevPop |
Population standard deviation |
$stdDevSamp |
Sample standard deviation |
$top / $bottom
|
Top/bottom by sort |
$topN / $bottomN
|
Top/bottom N by sort |
$firstN / $lastN
|
First/last N values |
$maxN / $minN
|
Max/min N values |
$accumulator |
Custom JavaScript accumulator (requires JsTriggers) |
Available in $setWindowFields:
$sum, $avg, $min, $max, $count, $push, $addToSet, $first, $last, $stdDevPop, $stdDevSamp, $rank, $denseRank, $documentNumber, $shift, $expMovingAvg, $derivative, $integral, $covariancePop, $covarianceSamp, $linearFill, $locf
$add, $subtract, $multiply, $divide, $mod, $abs, $ceil, $floor, $round, $trunc, $pow, $sqrt, $log, $log10, $ln, $exp
$sin, $cos, $tan, $asin, $acos, $atan, $atan2, $degreesToRadians, $radiansToDegrees
$concat, $toLower, $toUpper, $trim, $ltrim, $rtrim, $substr, $substrBytes, $substrCP, $strLenBytes, $strLenCP, $indexOfBytes, $indexOfCP, $split, $strcasecmp, $replaceOne, $replaceAll, $regexMatch, $regexFind, $regexFindAll
$cmp, $eq, $ne, $gt, $gte, $lt, $lte
$cond, $ifNull, $switch
$and, $or, $not
$arrayElemAt, $size, $isArray, $concatArrays, $in, $filter, $map, $reduce, $reverseArray, $range, $slice, $first, $last, $sortArray, $objectToArray, $arrayToObject, $zip
$type, $convert, $toBool, $toInt, $toLong, $toDouble, $toDecimal, $toString, $toDate, $toObjectId, $isNumber
$year, $month, $dayOfMonth, $hour, $minute, $second, $millisecond, $dayOfWeek, $dayOfYear, $dateToString, $dateFromString, $dateAdd, $dateSubtract, $dateDiff
$mergeObjects, $getField, $setField
$literal, $let, $binarySize, $bsonSize, $rand, $sampleRate, $toHashedIndexKey, $function (requires JsTriggers)
$tsIncrement, $tsSecond
- Filter & Update Operators — Query and update operators
- LINQ Support — LINQ-based querying
- Features — Full feature overview
Getting Started
Integration & Dependency Injection
Data Management
Reference
- Feature Comparison
- Features
- Filter & Update Operators
- Aggregation Pipeline
- LINQ Support
- API Reference
Help