Skip to content

Commit c1b5c51

Browse files
committed
types: correct Median implementation
1 parent 3d67419 commit c1b5c51

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

test/types/PipelineStage.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,3 @@ const vectorSearchStages: PipelineStage[] = [
575575
}
576576
}
577577
];
578-
579-
function median() {
580-
const medianStage: PipelineStage = {
581-
$median: {
582-
input: ['$test01', '$test02', '$test03'],
583-
method: 'approximate'
584-
}
585-
};
586-
}

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: 14 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 |

types/pipelinestage.d.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ declare module 'mongoose' {
2020
| PipelineStage.ListSessions
2121
| PipelineStage.Lookup
2222
| PipelineStage.Match
23-
| PipelineStage.Median
2423
| PipelineStage.Merge
2524
| PipelineStage.Out
2625
| PipelineStage.PlanCacheStats
@@ -188,14 +187,6 @@ declare module 'mongoose' {
188187
$match: FilterQuery<any>;
189188
}
190189

191-
export interface Median {
192-
/** [`$median` reference](https://www.mongodb.com/docs/v7.0/reference/operator/aggregation/median/) */
193-
$median: {
194-
input: number | Expression,
195-
method: 'approximate'
196-
}
197-
}
198-
199190
export interface Merge {
200191
/** [`$merge` reference](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) */
201192
$merge: {

0 commit comments

Comments
 (0)