mongoose 6.2.6 → 6.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +35 -26
- package/CHANGELOG.md +30 -0
- package/dist/browser.umd.js +83 -75
- package/lib/browserDocument.js +1 -0
- package/lib/connection.js +4 -4
- package/lib/cursor/AggregationCursor.js +0 -1
- package/lib/cursor/QueryCursor.js +2 -1
- package/lib/document.js +49 -11
- package/lib/helpers/document/handleSpreadDoc.js +19 -1
- package/lib/helpers/query/castFilterPath.js +0 -1
- package/lib/index.js +1 -3
- package/lib/model.js +78 -67
- package/lib/options/SchemaDateOptions.js +8 -1
- package/lib/query.js +41 -13
- package/lib/queryhelpers.js +17 -0
- package/lib/schema/SubdocumentPath.js +4 -1
- package/lib/schema/array.js +1 -0
- package/lib/schema/documentarray.js +14 -7
- package/lib/schema.js +14 -4
- package/lib/schematype.js +3 -1
- package/lib/types/array/methods/index.js +2 -0
- package/lib/virtualtype.js +1 -0
- package/package.json +12 -11
- package/tools/repl.js +8 -8
- package/tools/sharded.js +3 -3
- package/types/connection.d.ts +116 -116
- package/types/document.d.ts +3 -0
- package/types/error.d.ts +2 -2
- package/types/index.d.ts +73 -178
- package/types/mongooseoptions.d.ts +180 -0
- package/types/pipelinestage.d.ts +194 -194
- package/types/schemaoptions.d.ts +8 -2
package/types/pipelinestage.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare module 'mongoose' {
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
3
|
* [Stages reference](https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/#aggregation-pipeline-stages)
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
export type PipelineStage =
|
|
6
6
|
| PipelineStage.AddFields
|
|
7
7
|
| PipelineStage.Bucket
|
|
8
8
|
| PipelineStage.BucketAuto
|
|
@@ -33,240 +33,240 @@ declare module 'mongoose' {
|
|
|
33
33
|
| PipelineStage.SortByCount
|
|
34
34
|
| PipelineStage.UnionWith
|
|
35
35
|
| PipelineStage.Unset
|
|
36
|
-
| PipelineStage.Unwind
|
|
36
|
+
| PipelineStage.Unwind;
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
export namespace PipelineStage {
|
|
39
|
+
export interface AddFields {
|
|
40
|
+
/** [`$addFields` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/) */
|
|
41
|
+
$addFields: Record<string, any>
|
|
42
|
+
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
44
|
+
export interface Bucket {
|
|
45
|
+
/** [`$bucket` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucket/) */
|
|
46
|
+
$bucket: {
|
|
47
|
+
groupBy: any
|
|
48
|
+
boundaries: any[]
|
|
49
|
+
default?: any
|
|
50
|
+
output?: Record<string, { [op in AccumulatorOperator]?: any }>
|
|
52
51
|
}
|
|
52
|
+
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
54
|
+
export interface BucketAuto {
|
|
55
|
+
/** [`$bucketAuto` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/) */
|
|
56
|
+
$bucketAuto: {
|
|
57
|
+
groupBy: any
|
|
58
|
+
buckets: number
|
|
59
|
+
output?: Record<string, { [op in AccumulatorOperator]?: any }>
|
|
60
|
+
granularity?: 'R5' | 'R10' | 'R20' | 'R40' | 'R80' | '1-2-5' | 'E6' | 'E12' | 'E24' | 'E48' | 'E96' | 'E192' | 'POWERSOF2'
|
|
62
61
|
}
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
64
|
+
export interface CollStats {
|
|
65
|
+
/** [`$collStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/collStats/) */
|
|
66
|
+
$collStats: {
|
|
67
|
+
latencyStats?: { histograms?: boolean }
|
|
68
|
+
storageStats?: { scale?: number }
|
|
69
|
+
count?: {}
|
|
70
|
+
queryExecStats?: {}
|
|
72
71
|
}
|
|
72
|
+
}
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
export interface Count {
|
|
75
|
+
/** [`$count` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/count/) */
|
|
76
|
+
$count: string
|
|
77
|
+
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
export interface Facet {
|
|
80
|
+
/** [`$facet` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/facet/) */
|
|
81
|
+
$facet: Record<string, FacetPipelineStage[]>
|
|
82
|
+
}
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
84
|
+
export type FacetPipelineStage = Exclude<PipelineStage, PipelineStage.CollStats | PipelineStage.Facet | PipelineStage.GeoNear | PipelineStage.IndexStats | PipelineStage.Out | PipelineStage.Merge | PipelineStage.PlanCacheStats>;
|
|
85
|
+
|
|
86
|
+
export interface GeoNear {
|
|
87
|
+
/** [`$geoNear` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/) */
|
|
88
|
+
$geoNear: {
|
|
89
|
+
near: { type: 'Point'; coordinates: [number, number] } | [number, number]
|
|
90
|
+
distanceField: string
|
|
91
|
+
distanceMultiplier?: number
|
|
92
|
+
includeLocs?: string
|
|
93
|
+
key?: string
|
|
94
|
+
maxDistance?: number
|
|
95
|
+
minDistance?: number
|
|
96
|
+
query?: AnyObject
|
|
97
|
+
spherical?: boolean
|
|
98
|
+
uniqueDocs?: boolean
|
|
100
99
|
}
|
|
100
|
+
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
102
|
+
export interface GraphLookup {
|
|
103
|
+
/** [`$graphLookup` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/) */
|
|
104
|
+
$graphLookup: {
|
|
105
|
+
from: string
|
|
106
|
+
startWith: any
|
|
107
|
+
connectFromField: string
|
|
108
|
+
connectToField: string
|
|
109
|
+
as: string
|
|
110
|
+
maxDepth?: number
|
|
111
|
+
depthField?: string
|
|
112
|
+
restrictSearchWithMatch?: AnyObject
|
|
114
113
|
}
|
|
114
|
+
}
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
export interface Group {
|
|
117
|
+
/** [`$group` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/group) */
|
|
118
|
+
$group: { _id: any } | { [key: string]: { [op in AccumulatorOperator]?: any } }
|
|
119
|
+
}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
export interface IndexStats {
|
|
122
|
+
/** [`$indexStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/) */
|
|
123
|
+
$indexStats: {}
|
|
124
|
+
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
export interface Limit {
|
|
127
|
+
/** [`$limit` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/limit/) */
|
|
128
|
+
$limit: number
|
|
129
|
+
}
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
export interface ListSessions {
|
|
132
|
+
/** [`$listSessions` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/listSessions/) */
|
|
133
|
+
$listSessions: { users?: { user: string; db: string }[] } | { allUsers?: true }
|
|
134
|
+
}
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
136
|
+
export interface Lookup {
|
|
137
|
+
/** [`$lookup` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/) */
|
|
138
|
+
$lookup: {
|
|
139
|
+
from: string
|
|
140
|
+
as: string
|
|
141
|
+
localField?: string
|
|
142
|
+
foreignField?: string
|
|
143
|
+
let?: Record<string, any>
|
|
144
|
+
pipeline?: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out | PipelineStage.Search>[]
|
|
146
145
|
}
|
|
146
|
+
}
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
export interface Match {
|
|
149
|
+
/** [`$match` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) */
|
|
150
|
+
$match: AnyObject
|
|
151
|
+
}
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
153
|
+
export interface Merge {
|
|
154
|
+
/** [`$merge` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/merge/) */
|
|
155
|
+
$merge: {
|
|
156
|
+
into: string | { db: string; coll: string }
|
|
157
|
+
on?: string | string[]
|
|
158
|
+
let?: Record<string, any>
|
|
159
|
+
whenMatched?: 'replace' | 'keepExisting' | 'merge' | 'fail' | Extract<PipelineStage, PipelineStage.AddFields | PipelineStage.Set | PipelineStage.Project | PipelineStage.Unset | PipelineStage.ReplaceRoot | PipelineStage.ReplaceWith>[]
|
|
160
|
+
whenNotMatched?: 'insert' | 'discard' | 'fail'
|
|
162
161
|
}
|
|
162
|
+
}
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
export interface Out {
|
|
165
|
+
/** [`$out` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/out/) */
|
|
166
|
+
$out: string | { db: string; coll: string }
|
|
167
|
+
}
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
export interface PlanCacheStats {
|
|
170
|
+
/** [`$planCacheStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/planCacheStats/) */
|
|
171
|
+
$planCacheStats: {}
|
|
172
|
+
}
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
export interface Project {
|
|
175
|
+
/** [`$project` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/project/) */
|
|
176
|
+
$project: { [field: string]: any }
|
|
177
|
+
}
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
export interface Redact {
|
|
180
|
+
/** [`$redact` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/redact/) */
|
|
181
|
+
$redact: any
|
|
182
|
+
}
|
|
183
183
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
184
|
+
export interface ReplaceRoot {
|
|
185
|
+
/** [`$replaceRoot` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceRoot/) */
|
|
186
|
+
$replaceRoot: { newRoot: any }
|
|
187
|
+
}
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
export interface ReplaceWith {
|
|
190
|
+
/** [`$replaceWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/) */
|
|
191
|
+
$replaceWith: any
|
|
192
|
+
}
|
|
193
193
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
export interface Sample {
|
|
195
|
+
/** [`$sample` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sample/) */
|
|
196
|
+
$sample: { size: number }
|
|
197
|
+
}
|
|
198
198
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
export interface Search {
|
|
200
|
+
/** [`$search` reference](https://docs.atlas.mongodb.com/reference/atlas-search/query-syntax/) */
|
|
201
|
+
$search: {
|
|
202
|
+
index?: string;
|
|
203
|
+
highlight?: {
|
|
204
204
|
/** [`highlightPath` reference](https://docs.atlas.mongodb.com/atlas-search/path-construction/#multiple-field-search) */
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
205
|
+
path: string | string[] | { value: string, multi: string };
|
|
206
|
+
maxCharsToExamine?: number;
|
|
207
|
+
maxNumPassages?: number;
|
|
208
|
+
};
|
|
209
|
+
[key: string]: any;
|
|
211
210
|
}
|
|
211
|
+
}
|
|
212
212
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
export interface Set {
|
|
214
|
+
/** [`$set` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/set/) */
|
|
215
|
+
$set: Record<string, any>
|
|
216
|
+
}
|
|
217
217
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
>
|
|
218
|
+
export interface SetWindowFields {
|
|
219
|
+
/** [`$setWindowFields` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/setWindowFields/) */
|
|
220
|
+
$setWindowFields: {
|
|
221
|
+
partitionBy?: any
|
|
222
|
+
sortBy?: Record<string, 1 | -1>
|
|
223
|
+
output: Record<
|
|
224
|
+
string,
|
|
225
|
+
{ [op in WindowOperator]?: any } & {
|
|
226
|
+
window?: {
|
|
227
|
+
documents?: [string | number, string | number]
|
|
228
|
+
range?: [string | number, string | number]
|
|
229
|
+
unit?: 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond'
|
|
230
|
+
}
|
|
233
231
|
}
|
|
232
|
+
>
|
|
234
233
|
}
|
|
234
|
+
}
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
export interface Skip {
|
|
237
|
+
/** [`$skip` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/skip/) */
|
|
238
|
+
$skip: number
|
|
239
|
+
}
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
241
|
+
export interface Sort {
|
|
242
|
+
/** [`$sort` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sort/) */
|
|
243
|
+
$sort: Record<string, 1 | -1 | { $meta: 'textScore' }>
|
|
244
|
+
}
|
|
245
245
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
246
|
+
export interface SortByCount {
|
|
247
|
+
/** [`$sortByCount` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sortByCount/) */
|
|
248
|
+
$sortByCount: any
|
|
249
|
+
}
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
251
|
+
export interface UnionWith {
|
|
252
|
+
/** [`$unionWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unionWith/) */
|
|
253
|
+
$unionWith:
|
|
254
|
+
| string
|
|
255
|
+
| { coll: string; pipeline?: Exclude<PipelineStage, PipelineStage.Out | PipelineStage.Merge>[] }
|
|
256
|
+
}
|
|
257
257
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
258
|
+
export interface Unset {
|
|
259
|
+
/** [`$unset` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unset/) */
|
|
260
|
+
$unset: string | string[]
|
|
261
|
+
}
|
|
262
262
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
263
|
+
export interface Unwind {
|
|
264
|
+
/** [`$unwind` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/) */
|
|
265
|
+
$unwind: string | { path: string; includeArrayIndex?: string; preserveNullAndEmptyArrays?: boolean }
|
|
266
|
+
}
|
|
267
267
|
|
|
268
|
-
type AccumulatorOperator = '$accumulator' | '$addToSet' | '$avg' | '$count' | '$first' | '$last' | '$max' | '$mergeObjects' | '$min' | '$push' | '$stdDevPop' | '$stdDevSamp' | '$sum'
|
|
268
|
+
type AccumulatorOperator = '$accumulator' | '$addToSet' | '$avg' | '$count' | '$first' | '$last' | '$max' | '$mergeObjects' | '$min' | '$push' | '$stdDevPop' | '$stdDevSamp' | '$sum';
|
|
269
269
|
|
|
270
|
-
type WindowOperator = '$addToSet' | '$avg' | '$count' | '$covariancePop' | '$covarianceSamp' | '$derivative' | '$expMovingAvg' | '$integral' | '$max' | '$min' | '$push' | '$stdDevSamp' | '$stdDevPop' | '$sum' | '$first' | '$last' | '$shift' | '$denseRank' | '$documentNumber' | '$rank'
|
|
271
|
-
}
|
|
270
|
+
type WindowOperator = '$addToSet' | '$avg' | '$count' | '$covariancePop' | '$covarianceSamp' | '$derivative' | '$expMovingAvg' | '$integral' | '$max' | '$min' | '$push' | '$stdDevSamp' | '$stdDevPop' | '$sum' | '$first' | '$last' | '$shift' | '$denseRank' | '$documentNumber' | '$rank';
|
|
272
271
|
}
|
|
272
|
+
}
|
package/types/schemaoptions.d.ts
CHANGED
|
@@ -43,6 +43,12 @@ declare module 'mongoose' {
|
|
|
43
43
|
/** The timeseries option to use when creating the model's collection. */
|
|
44
44
|
timeseries?: mongodb.TimeSeriesCollectionOptions;
|
|
45
45
|
|
|
46
|
+
/** The number of seconds after which a document in a timeseries collection expires. */
|
|
47
|
+
expireAfterSeconds?: number;
|
|
48
|
+
|
|
49
|
+
/** The time after which a document in a timeseries collection expires. */
|
|
50
|
+
expires?: number | string;
|
|
51
|
+
|
|
46
52
|
/**
|
|
47
53
|
* Mongoose by default produces a collection name by passing the model name to the utils.toCollectionName
|
|
48
54
|
* method. This method pluralizes the name. Set this option if you need a different name for your collection.
|
|
@@ -158,7 +164,7 @@ declare module 'mongoose' {
|
|
|
158
164
|
* incremented even if these paths are updated). DO NOT do this unless you know what you're doing.
|
|
159
165
|
* For subdocuments, include this on the parent document using the fully qualified path.
|
|
160
166
|
*/
|
|
161
|
-
skipVersioning?: {[key: string]: boolean; };
|
|
167
|
+
skipVersioning?: { [key: string]: boolean; };
|
|
162
168
|
/**
|
|
163
169
|
* Validation errors in a single nested schema are reported
|
|
164
170
|
* both on the child and on the parent schema.
|
|
@@ -178,6 +184,6 @@ declare module 'mongoose' {
|
|
|
178
184
|
* You can suppress the warning by setting { supressReservedKeysWarning: true } schema options. Keep in mind that this
|
|
179
185
|
* can break plugins that rely on these reserved names.
|
|
180
186
|
*/
|
|
181
|
-
|
|
187
|
+
supressReservedKeysWarning?: boolean
|
|
182
188
|
}
|
|
183
189
|
}
|