most widely used aggregation stages and aggregation operators list down all of them
- User
most widely used aggregation stages and aggregation operators list down all of them
- Assistant
- User
- Assistant
most widely used aggregation stages and aggregation operators list down all of them
MongoDB provides a rich set of aggregation stages and operators that allow for complex data processing and analysis. Here’s a comprehensive list of the most widely used aggregation stages and operators:
Aggregation Stages
$match: Filters documents to pass only the documents that match the specified condition(s) to the next pipeline stage.
$group: Groups input documents by a specified identifier expression and applies the accumulator expressions to each group.
$project: each document in the stream by including, excluding, or adding new fields.
$sort: Sorts all input documents and returns them in order to the next stage.
$limit: Passes the first N documents unmodified to the pipeline where N is the specified limit.
$skip: Skips the first N documents where N is the specified number and passes the remaining documents to the next stage.
$unwind: Deconstructs an array field from the input documents to output a document for each element.
$lookup: Performs a left outer join to a collection in the same database to filter in documents from the “joined” collection for processing.
$addFields: Adds new fields to documents.
$replaceRoot: Replaces the input document with the specified document.
$facet: Processes multiple aggregation pipelines within a single stage on the same set of input documents.
$bucket: Categorizes incoming documents into a specified number of groups, called buckets.
$bucketAuto: Automatically categorizes documents into buckets with approximately equal numbers of documents.
$count: Returns a count of the number of documents at this stage of the aggregation pipeline.
$sortByCount: Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.
$graphLookup: Performs a recursive search on a collection.
$addToSet: Returns an array of unique values that result from applying an expression to each document in a group.
$out: Writes the results of the aggregation pipeline to a specified collection.
outbut with more flexibility.
$match: Filters documents to pass only the documents that match the specified condition(s) to the next pipeline stage.
$group: Groups input documents by a specified identifier expression and applies the accumulator expressions to each group.
$project: each document in the stream by including, excluding, or adding new fields.
$sort: Sorts all input documents and returns them in order to the next stage.
$limit: Passes the first N documents unmodified to the pipeline where N is the specified limit.
$skip: Skips the first N documents where N is the specified number and passes the remaining documents to the next stage.
$unwind: Deconstructs an array field from the input documents to output a document for each element.
$lookup: Performs a left outer join to a collection in the same database to filter in documents from the “joined” collection for processing.
$addFields: Adds new fields to documents.
$replaceRoot: Replaces the input document with the specified document.
$facet: Processes multiple aggregation pipelines within a single stage on the same set of input documents.
$bucket: Categorizes incoming documents into a specified number of groups, called buckets.
$bucketAuto: Automatically categorizes documents into buckets with approximately equal numbers of documents.
$count: Returns a count of the number of documents at this stage of the aggregation pipeline.
$sortByCount: Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.
$graphLookup: Performs a recursive search on a collection.
$addToSet: Returns an array of unique values that result from applying an expression to each document in a group.
$out: Writes the results of the aggregation pipeline to a specified collection.
outbut with more flexibility.
Aggregation Operators
Arithmetic Operators
$add: Adds numbers.
$subtract: Subtracts numbers.
$multiply: Multiplies numbers.
$divide: Divides numbers.
$mod: Takes the modulus of numbers.
$add: Adds numbers.
$subtract: Subtracts numbers.
$multiply: Multiplies numbers.
$divide: Divides numbers.
$mod: Takes the modulus of numbers.
Array Operators
$arrayElemAt: Returns the element at the specified array index.
$arrayToObject: Converts an array to an object.
$concatArrays: arrays.
$filter: Selects a subset of the array to return based on the specified condition.
$indexOfArray: Searches an array for an occurrence of a specified value and returns the array index (zero-based) of the first occurrence.
$isArray: Checks if the operand is an array.
$map: Applies an expression to each element in an array and returns an array with the applied results.
$range: Outputs an array containing a sequence of integers.
$reduce: Applies an expression to each element in an array and combines them into a single value.
$reverseArray: Reverses the order of elements in an array.
$size: Returns the number of elements in an array.
$slice: Returns a subset of an array.
$zip: arrays together.
$arrayElemAt: Returns the element at the specified array index.
$arrayToObject: Converts an array to an object.
$concatArrays: arrays.
$filter: Selects a subset of the array to return based on the specified condition.
$indexOfArray: Searches an array for an occurrence of a specified value and returns the array index (zero-based) of the first occurrence.
$isArray: Checks if the operand is an array.
$map: Applies an expression to each element in an array and returns an array with the applied results.
$range: Outputs an array containing a sequence of integers.
$reduce: Applies an expression to each element in an array and combines them into a single value.
$reverseArray: Reverses the order of elements in an array.
$size: Returns the number of elements in an array.
$slice: Returns a subset of an array.
$zip: arrays together.
Boolean Operators
$and: Returns true if all the expressions are true.
$or: Returns true if any of the expressions are true.
$not: Returns the boolean value that is the opposite of the expression's result.
$and: Returns true if all the expressions are true.
$or: Returns true if any of the expressions are true.
$not: Returns the boolean value that is the opposite of the expression's result.
Comparison Operators
$cmp: Compares two values.
$eq: Returns true if the values are equal.
$gt: Returns true if the first value is greater than the second.
$gte: Returns true if the first value is greater than or equal to the second.
$lt: Returns true if the first value is less than the second.
$lte: Returns true if the first value is less than or equal to the second.
$ne: Returns true if the values are not equal.
$cmp: Compares two values.
$eq: Returns true if the values are equal.
$gt: Returns true if the first value is greater than the second.
$gte: Returns true if the first value is greater than or equal to the second.
$lt: Returns true if the first value is less than the second.
$lte: Returns true if the first value is less than or equal to the second.
$ne: Returns true if the values are not equal.
Conditional Operators
$cond: Evaluates a boolean expression to return one of two specified return expressions.
$ifNull: Returns the first non-null expression.
$switch: Evaluates a series of case expressions and returns the first true case.
$cond: Evaluates a boolean expression to return one of two specified return expressions.
$ifNull: Returns the first non-null expression.
$switch: Evaluates a series of case expressions and returns the first true case.
Date Operators
$dateFromParts: Creates a date from parts.
$dateToParts: Returns a document containing the constituent parts of a date.
$dateFromString: Converts a date/time string to a date object.
$dateToString: Converts a date object to a string according to a specified format.
$dayOfMonth: Returns the day of the month for a date as a number between 1 and 31.
$dayOfWeek: Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday).
$dayOfYear: Returns the day of the year for a date as a number between 1 and 366.
$hour: Returns the hour for a date as a number between 0 and 23.
$isoDayOfWeek: Returns the ISO day of the week for a date as a number between 1 (Monday) and 7 (Sunday).
$isoWeek: Returns the ISO week of the year for a date as a number between 1 and 53.
$isoWeekYear: Returns the ISO week year for a date as a number.
$millisecond: Returns the milliseconds of a date as a number between 0 and 999.
$minute: Returns the minutes of a date as a number between 0 and 59.
$month: Returns the month of a date as a number between 1 and 12.
$second: Returns the seconds of a date as a number between 0 and 59.
$week: Returns the week of the year for a date as a number between 0 and 53.
$year: Returns the year for a date as a number.
$dateFromParts: Creates a date from parts.
$dateToParts: Returns a document containing the constituent parts of a date.
$dateFromString: Converts a date/time string to a date object.
$dateToString: Converts a date object to a string according to a specified format.
$dayOfMonth: Returns the day of the month for a date as a number between 1 and 31.
$dayOfWeek: Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday).
$dayOfYear: Returns the day of the year for a date as a number between 1 and 366.
$hour: Returns the hour for a date as a number between 0 and 23.
$isoDayOfWeek: Returns the ISO day of the week for a date as a number between 1 (Monday) and 7 (Sunday).
$isoWeek: Returns the ISO week of the year for a date as a number between 1 and 53.
$isoWeekYear: Returns the ISO week year for a date as a number.
$millisecond: Returns the milliseconds of a date as a number between 0 and 999.
$minute: Returns the minutes of a date as a number between 0 and 59.
$month: Returns the month of a date as a number between 1 and 12.
$second: Returns the seconds of a date as a number between 0 and 59.
$week: Returns the week of the year for a date as a number between 0 and 53.
$year: Returns the year for a date as a number.
Miscellaneous Operators
$type: Returns the BSON data type of the field.
$literal: Returns a value without parsing.
$type: Returns the BSON data type of the field.
$literal: Returns a value without parsing.
Object Operators
$mergeObjects: Merges multiple documents into a single document.
$objectToArray: Converts a document to an array of key-value pairs.
$mergeObjects: Merges multiple documents into a single document.
$objectToArray: Converts a document to an array of key-value pairs.
Set Operators
$allElementsTrue: Returns true if all elements of the set evaluate to true.
$anyElementTrue: Returns true if any element of the set evaluates to true.
$setDifference: Returns elements of the first set that do not appear in the second set.
$setEquals: Returns true if the input sets are equal.
$setIntersection: Returns a set that contains all elements that appear in every input set.
$setIsSubset: Returns true if all elements of the first set appear in the second set.
$setUnion: Returns a set that contains all elements from all input sets.
$allElementsTrue: Returns true if all elements of the set evaluate to true.
$anyElementTrue: Returns true if any element of the set evaluates to true.
$setDifference: Returns elements of the first set that do not appear in the second set.
$setEquals: Returns true if the input sets are equal.
$setIntersection: Returns a set that contains all elements that appear in every input set.
$setIsSubset: Returns true if all elements of the first set appear in the second set.
$setUnion: Returns a set that contains all elements from all input sets.
String Operators
$concat: strings.
$indexOfBytes: Searches a string for an occurrence of a substring and returns the UTF-8 byte index.
$indexOfCP: Searches a string for an occurrence of a substring and returns the UTF-8 code point index.
$split: Splits a string into substrings based on a delimiter.
$strLenBytes: Returns the number of UTF-8 encoded bytes in a string.
$strLenCP: Returns the number of UTF-8 code points in a string.
$strcasecmp: Performs a case-insensitive comparison.
$substr: Returns a substring of a string.
$substrBytes: Returns a substring of a string, based on a number of bytes.
$substrCP: Returns a substring of a string, based on a number of code points.
$toLower: Converts a string to lowercase.
$toUpper: Converts a string to uppercase.
$trim: Removes whitespace or the specified characters from the beginning and end of a string.
$ltrim: Removes whitespace or the specified characters from the beginning of a string.
$rtrim: Removes whitespace or the specified characters from the end of a string.
$concat: strings.
$indexOfBytes: Searches a string for an occurrence of a substring and returns the UTF-8 byte index.
$indexOfCP: Searches a string for an occurrence of a substring and returns the UTF-8 code point index.
$split: Splits a string into substrings based on a delimiter.
$strLenBytes: Returns the number of UTF-8 encoded bytes in a string.
$strLenCP: Returns the number of UTF-8 code points in a string.
$strcasecmp: Performs a case-insensitive comparison.
$substr: Returns a substring of a string.
$substrBytes: Returns a substring of a string, based on a number of bytes.
$substrCP: Returns a substring of a string, based on a number of code points.
$toLower: Converts a string to lowercase.
$toUpper: Converts a string to uppercase.
$trim: Removes whitespace or the specified characters from the beginning and end of a string.
$ltrim: Removes whitespace or the specified characters from the beginning of a string.
$rtrim: Removes whitespace or the specified characters from the end of a string.
These stages and operators allow for highly flexible and powerful data aggregation pipelines in MongoDB, enabling complex data processing directly within the database.
const agg = [ { 'match': { 'and': [ { 'serviceURL': testname }, { 'limsId': cityDetails.limsId } ] } }, { 'lookup': { 'from': 'branchservicesmappings', 'localField': 'serviceId', 'foreignField': 'serviceId', 'as': 'branchServicesDetails' } }, { 'unwind': { 'path': 'branchServicesDetails' } }, { 'match': { 'and': [ { 'branchServicesDetails.limsId': cityDetails.limsId }, { 'branchServicesDetails.branchId': branchId }, { 'branchServicesDetails.amount': { ne: 0 } } ] } }, { 'facet': { 'packageServiceDetails': [ { 'match': { 'isPopularPackage': 'true' } }, { 'lookup': { 'from': 'packageservicesdetails', 'localField': 'serviceId', 'foreignField': 'packageId', 'as': 'packageServices' } }, { 'unwind': { 'path': 'packageServices' } }, { 'match': { 'and': [ { 'packageServices.limsId': cityDetails.limsId }, { 'packageServices.isActive': true } ] } }, { 'lookup': { 'from': 'testlists', 'localField': 'packageServices.serviceId', 'foreignField': 'serviceId', 'as': 'packageServices.testLists' } }, { 'unwind': { 'path': 'packageServices.testLists' } }, { 'match': { 'and': [ { 'packageServices.testLists.limsId': cityDetails.limsId }, { 'or': [ { 'and': [ { 'packageServices.testLists.branchId': null }, { 'packageServices.testLists.isDefault': true } ] }, { 'and': [ { 'packageServices.testLists.branchId': branchId }, { 'packageServices.testLists.isDefault': false } ] } ] } ] } }, { 'addFields': { 'packageServices.testLists.testListInArr': { 'map': { 'input': { 'split': ['<REDACTED>', '|'] }, 'as': 'serviceName', 'in': { 'serviceName': '$$serviceName' } } }, 'packageServices.testLists.testListCount': { 'size': { '', '|'] } }, 'packageServices.testLists.packagOrder': { cond: { if: { eq: ["packageServices.packageServiceSortOrder", null] }, then: Infinity, else: "packageServices.packageServiceSortOrder" } } } }, { 'sort': { 'packageServices.testLists.branchId': -1 } }, { 'group': { '_id': { 'serviceId': 'packageServices.testLists.serviceId' }, 'limsId': { 'first': 'limsId' }, 'serviceObjectId': { 'first': '_id' }, 'serviceName': { 'first': 'serviceName' }, 'orderingInfo': { 'first': 'orderingInfo' }, 'isActive': { 'first': 'isActive' }, 'isShowInDOS': { 'first': 'isShowInDOS' }, 'isPopularPackage': { 'first': 'isPopularPackage' }, 'branchServicesDetails': { 'first': 'branchServicesDetails' }, 'packageServices': { 'first': 'packageServices' }, 'specimenName': { 'first': 'specimenName' }, 'patientPreparation': { 'first': 'patientPreparation' }, 'isHomeVisitNotApplicable': { 'first': { 'isHomeVisitNotApplicable' } }, 'applicableGender': { 'applicableGender' }, 'serviceId': { 'serviceId' } } }, { 'group': { '_id': { 'packageId': 'packageServices.packageId' }, 'limsId': { 'limsId' }, 'serviceObjectId': { 'serviceObjectId' }, 'orderingInfo': { 'orderingInfo' }, 'serviceName': { 'serviceName' }, 'isActive': { 'isActive' }, 'isShowInDOS': { 'isShowInDOS' }, 'isPopularPackage': { 'isPopularPackage' }, 'amount': { 'branchServicesDetails.amount' }, 'tATTotalMinutes': { 'branchServicesDetails.tATTotalMinutes' }, 'packageServicesDetails': { 'packageServices.testLists' }, 'specimenName': { 'branchServicesDetails.specimenName' }, 'patientPreparation': { 'patientPreparation' }, 'isHomeVisitNotApplicable': { 'first': { 'toBool': 'isHomeVisitNotApplicable' } }, 'applicableGender': { 'first': 'applicableGender' }, 'serviceId': { 'first': 'serviceId' }, 'serviceMrp': { 'first': 'branchServicesDetails.packageMrp' }, 'servicesIncluded': { 'sum': 'packageServices.testLists.testListCount' } } }, { 'set': { 'testParameters': { 'map': { 'input': { 'sortArray': { 'input': 'packageServicesDetails', 'sortBy': { 'packagOrder': 1, 'serviceName': 1 } } }, 'as': 'test', 'in': { 'limsId': '$$test.limsId', 'serviceName': '$$test.serviceName', 'packageOrder': '$$test.packagOrder', 'isDefault': '$$test.isDefault', 'testListInArr': '$$test.testListInArr', 'testListCount': '$$test.testListCount', 'serviceId': '$$test.serviceId', 'branchId': '$$test.branchId', 'packageOrder': '$$test.packagOrder' } } } } }, { 'project': { 'serviceId': 1, '_id': "serviceObjectId", 'serviceName': 1, 'amount': 1, 'serviceMrp': 1, 'isHomeVisitNotApplicable': 1, 'isShowInDOS': 1, 'isPopularPackage': 1, 'tATTotalMinutes': 1, 'applicableGender': 1, 'testParameters': 1, 'specimenName': 1, 'limsId': 1, 'servicesIncluded': 1, 'orderingInfo': 1, 'patientPreparation': 1, 'serviceDescription': 1, 'discountPercentage': { 'round': [ { 'multiply': [{ subtract: [1, { amount", "serviceMrp"] }] }, 100] }, 0 ] } } } ], 'testDetails': [ { 'match': { 'isShowInDOS': true } }, { 'lookup': { 'from': 'testlists', 'localField': 'serviceId', 'foreignField': 'serviceId', 'as': 'testListsDetails' } }, { 'unwind': { 'path': 'testListsDetails' } }, { 'match': { 'and': [ { 'testListsDetails.limsId': cityDetails.limsId }, { 'or': [ { 'and': [ { 'testListsDetails.branchId': null }, { 'testListsDetails.isDefault': true } ] }, { 'and': [ { 'testListsDetails.branchId': branchId }, { 'testListsDetails.isDefault': false } ] } ] } ] } }, { 'addFields': { 'testListsDetails.testListInArr': { 'map': { 'input': { 'testListsDetails.testList', '|'] }, 'as': 'serviceName', 'in': { 'serviceName': '$$serviceName' } } }, 'testListsDetails.testListCount': { 'size': { 'split': ['testListsDetails.testList', '|'] } } } }, { 'group': { '_id': { 'packageId': 'testListsDetails.serviceId' }, 'limsId': { 'first': 'limsId' }, 'serviceObjectId': { 'first': '_id' }, 'serviceName': { 'first': 'serviceName' }, 'isActive': { 'first': '$isActive' }, 'isShow from the above code extract the different stages and operators used in the above code and explain them
The provided MongoDB aggregation pipeline code is quite complex and involves multiple stages and operators. Let's break down the stages and operators used:
Aggregation Stages
match: Filters documents to pass only the documents that match the specified condition(s) to the next pipeline stage.jsonCopy code{ 'match': { '$and': [ { 'serviceURL': testname }, { 'limsId': cityDetails.limsId } ] } }
lookup: Performs a left outer join to a collection in the same database to filter in documents from the “joined” collection for processing.jsonCopy code{ 'lookup': { 'from': 'branchservicesmappings', 'localField': 'serviceId', 'foreignField': 'serviceId', 'as': 'branchServicesDetails' } }
unwind: Deconstructs an array field from the input documents to output a document for each element.jsonCopy code{ 'unwind': { 'path': '$branchServicesDetails' } }
facet: Processes multiple aggregation pipelines within a single stage on the same set of input documents.jsonCopy code{ 'facet': { 'packageServiceDetails': [ ... ], 'testDetails': [ ... ] } }
addFields: Adds new fields to documents.jsonCopy code{ 'addFields': { 'packageServices.testLists.testListInArr': { ... }, 'packageServices.testLists.testListCount': { ... }, 'packageServices.testLists.packagOrder': { ... } } }
sort: Sorts all input documents and returns them in order to the next stage.jsonCopy code{ 'sort': { 'packageServices.testLists.branchId': -1 } }
group: Groups input documents by a specified identifier expression and applies the accumulator expressions to each group.jsonCopy code{ 'group': { '_id': { 'serviceId': 'packageServices.testLists.serviceId' }, 'limsId': { 'first': 'limsId' }, 'serviceObjectId': { 'first': '_id' }, 'serviceName': { 'first': 'serviceName' }, 'orderingInfo': { 'first': 'orderingInfo' }, 'isActive': { 'first': 'isActive' }, 'isShowInDOS': { 'first': 'isShowInDOS' }, 'isPopularPackage': { 'first': 'isPopularPackage' }, 'branchServicesDetails': { 'first': 'branchServicesDetails' }, 'packageServices': { 'first': 'packageServices' }, 'specimenName': { 'first': 'specimenName' }, 'patientPreparation': { 'first': 'patientPreparation' }, 'isHomeVisitNotApplicable': { 'first': { 'isHomeVisitNotApplicable' } }, 'applicableGender': { 'applicableGender' }, 'serviceId': { 'serviceId' } } }
addFields, used to add new fields to documents.jsonCopy code{ '$set': { 'testParameters': { ... } } }
project: <REDACTED> each document in the stream by including, excluding, or adding new fields.jsonCopy code{ 'project': { 'serviceId': 1, '_id': "$serviceObjectId", 'serviceName': 1, 'amount': 1, 'serviceMrp': 1, 'isHomeVisitNotApplicable': 1, 'isShowInDOS': 1, 'isPopularPackage': 1, 'tATTotalMinutes': 1, 'applicableGender': 1, 'testParameters': 1, 'specimenName': 1, 'limsId': 1, 'servicesIncluded': 1, 'orderingInfo': 1, 'patientPreparation': 1, 'serviceDescription': 1, 'discountPercentage': { ... } } }
$match: Filters documents to pass only the documents that match the specified condition(s) to the next pipeline stage.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'match': { 'and': [ { 'serviceURL': testname }, { 'limsId': cityDetails.limsId } ] } }
$lookup: Performs a left outer join to a collection in the same database to filter in documents from the “joined” collection for processing.
────────────────────────────────────────────────────────────────────
jsonCopy code{ '$lookup': { 'from': 'branchservicesmappings', 'localField': 'serviceId', 'foreignField': 'serviceId', 'as': 'branchServicesDetails' } }
$unwind: Deconstructs an array field from the input documents to output a document for each element.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'unwind': { 'path': 'branchServicesDetails' } }
$facet: Processes multiple aggregation pipelines within a single stage on the same set of input documents.
────────────────────────────────────────────────────────────────────
jsonCopy code{ '$facet': { 'packageServiceDetails': [ ... ], 'testDetails': [ ... ] } }
$addFields: Adds new fields to documents.
────────────────────────────────────────────────────────────────────
jsonCopy code{ '$addFields': { 'packageServices.testLists.testListInArr': { ... }, 'packageServices.testLists.testListCount': { ... }, 'packageServices.testLists.packagOrder': { ... } } }
$sort: Sorts all input documents and returns them in order to the next stage.
────────────────────────────────────────────────────────────────────
jsonCopy code{ '$sort': { 'packageServices.testLists.branchId': -1 } }
$group: Groups input documents by a specified identifier expression and applies the accumulator expressions to each group.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'group': { '_id': { 'serviceId': 'packageServices.testLists.serviceId' }, 'limsId': { 'limsId' }, 'serviceObjectId': { '_id' }, 'serviceName': { 'serviceName' }, 'orderingInfo': { 'orderingInfo' }, 'isActive': { 'isActive' }, 'isShowInDOS': { 'isShowInDOS' }, 'isPopularPackage': { 'isPopularPackage' }, 'branchServicesDetails': { 'branchServicesDetails' }, 'packageServices': { 'packageServices' }, 'specimenName': { 'specimenName' }, 'patientPreparation': { 'patientPreparation' }, 'isHomeVisitNotApplicable': { 'toBool': 'first': 'first': '$serviceId' } } }
addFields, used to add new fields to documents.
────────────────────────────────────────────────────────────────────
jsonCopy code{ '$set': { 'testParameters': { ... } } }
$project: each document in the stream by including, excluding, or adding new fields.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'project': { 'serviceId': 1, '_id': "serviceObjectId", 'serviceName': 1, 'amount': 1, 'serviceMrp': 1, 'isHomeVisitNotApplicable': 1, 'isShowInDOS': 1, 'isPopularPackage': 1, 'tATTotalMinutes': 1, 'applicableGender': 1, 'testParameters': 1, 'specimenName': 1, 'limsId': 1, 'servicesIncluded': 1, 'orderingInfo': 1, 'patientPreparation': 1, 'serviceDescription': 1, 'discountPercentage': { ... } } }
Aggregation Operators
and: Performs a logical AND operation on an array of two or more expressions.jsonCopy code{ 'match': { '$and': [ { 'serviceURL': testname }, { 'limsId': cityDetails.limsId } ] } }
ne: Matches documents where the value of the field is not equal to the specified value.jsonCopy code{ 'branchServicesDetails.amount': { ne: 0 } }
toBool: Converts a value to a boolean.jsonCopy code{ 'toBool': '$isHomeVisitNotApplicable' }
map: Applies an expression to each element in an array and returns an array with the applied results.jsonCopy code{ 'map': { 'input': { '', '|'] }, 'as': 'serviceName', 'in': { 'serviceName': '$$serviceName' } } }
split: Splits a string into substrings based on a delimiter.jsonCopy code{ 'split': ['$', '|'] }
size: Returns the number of elements in an array.jsonCopy code{ 'size': { '', '|'] } }
cond: Evaluates a boolean expression to return one of two specified return expressions.jsonCopy code{ cond: { if: { packageServices.packageServiceSortOrder", null] }, then: Infinity, else: "$packageServices.packageServiceSortOrder" } }
first: Returns the first element in an array of <REDACTED> code'limsId': { 'first': '$limsId' }
addToSet: Returns an array of unique values that result from applying an expression to each document in a <REDACTED> code'packageServicesDetails': { 'addToSet': '$packageServices.testLists' }
sum: Calculates and returns the sum of numeric values.jsonCopy code'servicesIncluded': { 'sum': '$packageServices.testLists.testListCount' }
round: Rounds a number to a specified place.jsonCopy code{ 'round': [ { 'multiply': [{ subtract: [1, { amount", "$serviceMrp"] }] }, 100] }, 0 ] }
divide: Divides one number by another and returns the result.jsonCopy code{ divide: ["serviceMrp"] }
subtract: Subtracts one number from another and returns the result.jsonCopy code{ subtract: [1, { amount", "$serviceMrp"] }] }
multiply: Multiplies numbers and returns the result.jsonCopy code{ 'multiply': [{ subtract: [1, { divide: ["serviceMrp"] }] }, 100] }
sortArray: Sorts an array based on a specified sort order.jsonCopy code{ 'sortArray': { 'input': '$packageServicesDetails', 'sortBy': { 'packagOrder': 1, 'serviceName': 1 } } }
$and: Performs a logical AND operation on an array of two or more expressions.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'match': { 'and': [ { 'serviceURL': testname }, { 'limsId': cityDetails.limsId } ] } }
$ne: Matches documents where the value of the field is not equal to the specified value.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'branchServicesDetails.amount': { $ne: 0 } }
$toBool: Converts a value to a boolean.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'isHomeVisitNotApplicable' }
$map: Applies an expression to each element in an array and returns an array with the applied results.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'map': { 'input': { 'split': ['$', '|'] }, 'as': 'serviceName', 'in': { 'serviceName': '$$serviceName' } } }
$split: Splits a string into substrings based on a delimiter.
────────────────────────────────────────────────────────────────────
jsonCopy code{ '', '|'] }
$size: Returns the number of elements in an array.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'size': { 'split': ['$', '|'] } }
$cond: Evaluates a boolean expression to return one of two specified return expressions.
────────────────────────────────────────────────────────────────────
jsonCopy code{ cond: { if: { eq: ["packageServices.packageServiceSortOrder", null] }, then: Infinity, else: "packageServices.packageServiceSortOrder" } }
$first: Returns the first element in an array of documents.
────────────────────────────────────────────────────────────────────
jsonCopy code'limsId': { 'limsId' }
$addToSet: Returns an array of unique values that result from applying an expression to each document in a group.
────────────────────────────────────────────────────────────────────
jsonCopy code'packageServicesDetails': { 'packageServices.testLists' }
$sum: Calculates and returns the sum of numeric values.
────────────────────────────────────────────────────────────────────
jsonCopy code'servicesIncluded': { 'packageServices.testLists.testListCount' }
$round: Rounds a number to a specified place.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'round': [ { 'multiply': [{ subtract: [1, { divide: ["serviceMrp"] }] }, 100] }, 0 ] }
$divide: Divides one number by another and returns the result.
────────────────────────────────────────────────────────────────────
jsonCopy code{ amount", "$serviceMrp"] }
$subtract: Subtracts one number from another and returns the result.
────────────────────────────────────────────────────────────────────
jsonCopy code{ subtract: [1, { divide: ["serviceMrp"] }] }
$multiply: Multiplies numbers and returns the result.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'multiply': [{ subtract: [1, { amount", "$serviceMrp"] }] }, 100] }
$sortArray: Sorts an array based on a specified sort order.
────────────────────────────────────────────────────────────────────
jsonCopy code{ 'sortArray': { 'input': 'packageServicesDetails', 'sortBy': { 'packagOrder': 1, 'serviceName': 1 } } }
These stages and operators work together to filter, join, unwind, group, and project the data, creating a complex aggregation pipeline that processes the data according to the specified requirements.
“most widely used aggregation stages and aggregation operators list down all of them.” Conversation with ChatGPT (version unspecified), from the ShareChat — Chatbot Conversations in the Wild dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m84tcdcw21d8q2f8mbpmfcxg
Not yet included in a published release.