Skip to content

Commit bd53c4c

Browse files
authored
Merge pull request #15233 from Automattic/vkarpov15/gh-15209
types: add missing $median operator to aggregation types
2 parents 52f3ced + 2de289b commit bd53c4c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

test/types/expressions.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,7 @@ const filterLimit: Expression.Filter = {
313313
}
314314
];
315315
})();
316+
317+
function gh15209() {
318+
const query: PipelineStage[] = [{ $group: { _id: null, median: { $median: { input: '$value', method: 'approximate' } } } }];
319+
}

types/expressions.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,18 @@ declare module 'mongoose' {
23012301
}
23022302
}
23032303

2304+
export interface Median {
2305+
/**
2306+
* Returns an approximation of the median, the 50th percentile, as a scalar value.
2307+
*
2308+
* @see https://www.mongodb.com/docs/v7.0/reference/operator/aggregation/median/
2309+
*/
2310+
$median: {
2311+
input: number | Expression,
2312+
method: 'approximate'
2313+
}
2314+
}
2315+
23042316
export interface StdDevPop {
23052317
/**
23062318
* Calculates the population standard deviation of the input values. Use if the values encompass the entire
@@ -2859,6 +2871,7 @@ declare module 'mongoose' {
28592871
Expression.Locf |
28602872
Expression.Max |
28612873
Expression.MaxN |
2874+
Expression.Median |
28622875
Expression.Min |
28632876
Expression.MinN |
28642877
Expression.Push |
@@ -2891,6 +2904,7 @@ declare module 'mongoose' {
28912904
Expression.ExpMovingAvg |
28922905
Expression.Integral |
28932906
Expression.Max |
2907+
Expression.Median |
28942908
Expression.Min |
28952909
Expression.StdDevPop |
28962910
Expression.StdDevSamp |
@@ -2963,6 +2977,7 @@ declare module 'mongoose' {
29632977
Expression.LastN |
29642978
Expression.Max |
29652979
Expression.MaxN |
2980+
Expression.Median |
29662981
Expression.MergeObjects |
29672982
Expression.Min |
29682983
Expression.MinN |

0 commit comments

Comments
 (0)