Skip to content

Commit a45ed3e

Browse files
committed
Merge branch '6.x' into 7.x
2 parents d881c3f + b331eac commit a45ed3e

File tree

5 files changed

+187
-2
lines changed

5 files changed

+187
-2
lines changed

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- 'website.js'
1111
- 'CHANGELOG.md'
1212
push:
13-
branches:ubuntu
13+
branches:
1414
- master
1515
paths:
1616
- '.github/workflows/documentation.yml'

docs/compatibility.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
</style>
1313

14-
Mongoose relies on the [MongoDB Node.js Driver](http://mongodb.github.io/node-mongodb-native/) to talk to MongoDB.
14+
Mongoose relies on the [MongoDB Node.js Driver](http://mongodb.github.io/node-mongodb-native/) to talk to MongoDB.
1515
You can refer to [this table](https://www.mongodb.com/docs/drivers/node/current/compatibility/) for up-to-date information as to which version of the MongoDB driver supports which version of MongoDB.
1616

1717
Below are the [semver](http://semver.org/) ranges representing which versions of mongoose are compatible with the listed versions of MongoDB server.
@@ -31,4 +31,6 @@ Below are the [semver](http://semver.org/) ranges representing which versions of
3131
| `2.6.x` | `^3.8.8 \| ^4.0.0 \| ^5.0.0` |
3232
| `2.4.x` | `^3.8.0 \| ^4.0.0` |
3333

34+
Mongoose `^6.5.0` also works with MongoDB server 7.x. But not all new MongoDB server 7.x features are supported by Mongoose 6.x.
35+
3436
Note that Mongoose `5.x` dropped support for all versions of MongoDB before `3.0.0`. If you need to use MongoDB `2.6` or older, use Mongoose `4.x`.

test/types/PipelineStage.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ const project14: PipelineStage = {
217217
}
218218
};
219219
const project15: PipelineStage = { $project: { item: 1, result: { $not: [{ $gt: ['$qty', 250] }] } } };
220+
const project16: PipelineStage = { $project: { maxScores: { $maxN: { input: '$scores', n: 3 } } } };
221+
const project17: PipelineStage = { $project: { first3Scores: { $firstN: { input: '$scores', n: 3 } } } };
220222

221223
const sort1: PipelineStage = { $sort: { count: -1 } };
222224
const sortByCount1: PipelineStage = { $sortByCount: '$tags' };
@@ -311,6 +313,21 @@ const setWindowFields4: PipelineStage = {
311313
}
312314
};
313315

316+
const setWindowFields5: PipelineStage = {
317+
$setWindowFields: {
318+
partitionBy: '$gameId',
319+
sortBy: { score: 1 },
320+
output: {
321+
minScores: {
322+
$firstN: { input: '$score', n: 3 }
323+
},
324+
maxScores: {
325+
$lastN: { input: '$score', n: 3 }
326+
}
327+
}
328+
}
329+
};
330+
314331
const setWindowFieldsLinearFill: PipelineStage = {
315332
$setWindowFields: {
316333
partitionBy: '$stock',
@@ -419,6 +436,27 @@ const group5: PipelineStage = {
419436
}
420437
};
421438
const group6: PipelineStage = { $group: { _id: '$author', books: { $push: '$title' } } };
439+
const group7: PipelineStage = {
440+
$group: {
441+
_id: '$gameId',
442+
topPlayers: {
443+
$topN: {
444+
output: ['$playerId', '$score'],
445+
sortBy: { score: -1 },
446+
n: 3
447+
}
448+
},
449+
bottomPlayers: {
450+
$bottomN: {
451+
output: ['$playerId', '$score'],
452+
sortBy: { score: 1 },
453+
n: 3
454+
}
455+
},
456+
maxScores: { $maxN: { input: '$score', n: 3 } },
457+
minScores: { $minN: { input: '$score', n: 3 } }
458+
}
459+
};
422460

423461
const stages1: PipelineStage[] = [
424462
// First Stage

test/types/expressions.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,49 @@ const timewithOffset430DateToString: Expression = { $dateToString: { format: '%H
7979
const minutesOffsetNYDateToString: Expression = { $dateToString: { format: '%Z', date: '$date', timezone: 'America/New_York' } };
8080
const minutesOffset430DateToString: Expression = { $dateToString: { format: '%Z', date: '$date', timezone: '+04:30' } };
8181

82+
const bottom: Expression.Bottom = {
83+
$bottom: {
84+
output: ['$playerId', '$score'],
85+
sortBy: { score: 1 }
86+
}
87+
};
88+
89+
const bottomN: Expression.BottomN = {
90+
$bottomN: {
91+
output: ['$playerId', '$score'],
92+
sortBy: { score: 1 },
93+
n: 3
94+
}
95+
};
96+
97+
const firstN: Expression.FirstN = {
98+
$firstN: {
99+
input: '$score',
100+
n: 3
101+
}
102+
};
103+
104+
const lastN: Expression.LastN = {
105+
$lastN: {
106+
input: '$score',
107+
n: 3
108+
}
109+
};
110+
111+
const maxN: Expression.MaxN = {
112+
$maxN: {
113+
input: '$score',
114+
n: 3
115+
}
116+
};
117+
118+
const minN: Expression.MinN = {
119+
$minN: {
120+
input: '$score',
121+
n: 3
122+
}
123+
};
124+
82125
const top: Expression.Top = {
83126
$top: {
84127
output: ['$playerId', '$score'],

types/expressions.d.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,21 @@ declare module 'mongoose' {
11501150
$first: Expression;
11511151
}
11521152

1153+
export interface FirstN {
1154+
/**
1155+
* $firstN can be used as an aggregation accumulator or array operator.
1156+
* As an aggregation accumulator, it returns an aggregation of the first n elements within a group.
1157+
* As an array operator, it returns the specified number of elements from the beginning of an array.
1158+
*
1159+
* @version 5.2
1160+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#mongodb-expression-exp.-first
1161+
*/
1162+
$firstN: {
1163+
input: Expression
1164+
n: Expression,
1165+
};
1166+
}
1167+
11531168
export interface In {
11541169
/**
11551170
* Returns a boolean indicating whether a specified value is in an array.
@@ -1190,6 +1205,21 @@ declare module 'mongoose' {
11901205
$last: Expression;
11911206
}
11921207

1208+
export interface LastN {
1209+
/**
1210+
* $lastN can be used as an aggregation accumulator or array operator.
1211+
* As an aggregation accumulator, it an aggregation of the last n elements within a group.
1212+
* As an array operator, it returns the specified number of elements from the end of an array.
1213+
*
1214+
* @version 5.2
1215+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#mongodb-group-grp.-lastN
1216+
*/
1217+
$lastN: {
1218+
input: Expression
1219+
n: Expression,
1220+
};
1221+
}
1222+
11931223
export interface LinearFill {
11941224
/**
11951225
* Fills null and missing fields in a window using linear interpolation based on surrounding field values.
@@ -2000,6 +2030,34 @@ declare module 'mongoose' {
20002030
$avg: Expression;
20012031
}
20022032

2033+
export interface Bottom {
2034+
/**
2035+
* Returns the bottom element within a group according to the specified sort order.
2036+
*
2037+
* @version 5.2
2038+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/#mongodb-group-grp.-bottom
2039+
*/
2040+
$bottom: {
2041+
sortBy: AnyObject,
2042+
output: Expression
2043+
};
2044+
}
2045+
2046+
export interface BottomN {
2047+
/**
2048+
* Returns an aggregation of the bottom n elements within a group, according to the specified sort order.
2049+
* If the group contains fewer than n elements, $bottomN returns all elements in the group.
2050+
*
2051+
* @version 5.2
2052+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/#mongodb-group-grp.-bottomN
2053+
*/
2054+
$bottomN: {
2055+
n: Expression,
2056+
sortBy: AnyObject,
2057+
output: Expression
2058+
};
2059+
}
2060+
20032061
export interface Count {
20042062
/**
20052063
* Returns the number of documents in a group.
@@ -2158,6 +2216,20 @@ declare module 'mongoose' {
21582216
$max: Expression | Expression[];
21592217
}
21602218

2219+
export interface MaxN {
2220+
/**
2221+
* Returns an aggregation of the maxmimum value n elements within a group.
2222+
* If the group contains fewer than n elements, $maxN returns all elements in the group.
2223+
*
2224+
* @version 5.2
2225+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/#mongodb-group-grp.-maxN
2226+
*/
2227+
$maxN: {
2228+
input: Expression
2229+
n: Expression,
2230+
};
2231+
}
2232+
21612233
export interface Min {
21622234
/**
21632235
* Returns the minimum value. $min compares both value and type, using the specified BSON comparison order for
@@ -2169,6 +2241,20 @@ declare module 'mongoose' {
21692241
$min: Expression | Expression[];
21702242
}
21712243

2244+
export interface MinN {
2245+
/**
2246+
* Returns an aggregation of the minimum value n elements within a group.
2247+
* If the group contains fewer than n elements, $minN returns all elements in the group.
2248+
*
2249+
* @version 5.2
2250+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/#mongodb-group-grp.-minN
2251+
*/
2252+
$minN: {
2253+
input: Expression
2254+
n: Expression,
2255+
};
2256+
}
2257+
21722258
export interface Push {
21732259
/**
21742260
* Returns an array of all values that result from applying an expression to documents.
@@ -2605,6 +2691,8 @@ declare module 'mongoose' {
26052691
export type ArrayExpressionOperatorReturningArray =
26062692
Expression.ConcatArrays |
26072693
Expression.Filter |
2694+
Expression.FirstN |
2695+
Expression.LastN |
26082696
Expression.Map |
26092697
Expression.ObjectToArray |
26102698
Expression.Range |
@@ -2763,12 +2851,16 @@ declare module 'mongoose' {
27632851
Expression.DocumentNumber |
27642852
Expression.ExpMovingAvg |
27652853
Expression.First |
2854+
Expression.FirstN |
27662855
Expression.Integral |
27672856
Expression.Last |
2857+
Expression.LastN |
27682858
Expression.LinearFill |
27692859
Expression.Locf |
27702860
Expression.Max |
2861+
Expression.MaxN |
27712862
Expression.Min |
2863+
Expression.MinN |
27722864
Expression.Push |
27732865
Expression.Rank |
27742866
Expression.Shift |
@@ -2783,6 +2875,10 @@ declare module 'mongoose' {
27832875

27842876
export type WindowOperatorReturningArray =
27852877
Expression.AddToSet |
2878+
Expression.FirstN |
2879+
Expression.LastN |
2880+
Expression.MaxN |
2881+
Expression.MinN |
27862882
Expression.Push;
27872883

27882884
export type WindowOperatorReturningNumber =
@@ -2858,12 +2954,18 @@ declare module 'mongoose' {
28582954
Expression.Accumulator |
28592955
Expression.AddToSet |
28602956
Expression.Avg |
2957+
Expression.Bottom |
2958+
Expression.BottomN |
28612959
Expression.Count |
28622960
Expression.First |
2961+
Expression.FirstN |
28632962
Expression.Last |
2963+
Expression.LastN |
28642964
Expression.Max |
2965+
Expression.MaxN |
28652966
Expression.MergeObjects |
28662967
Expression.Min |
2968+
Expression.MinN |
28672969
Expression.Push |
28682970
Expression.StdDevPop |
28692971
Expression.StdDevSamp |

0 commit comments

Comments
 (0)