mongoose 6.2.1 → 6.2.4
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 +5 -1
- package/.lgtm.yml +3 -0
- package/CHANGELOG.md +54 -0
- package/dist/browser.umd.js +156 -152
- package/index.js +5 -1
- package/lib/aggregate.js +22 -27
- package/lib/browserDocument.js +1 -1
- package/lib/cast/number.js +2 -3
- package/lib/cast.js +7 -4
- package/lib/connection.js +43 -21
- package/lib/cursor/AggregationCursor.js +12 -7
- package/lib/cursor/QueryCursor.js +11 -6
- package/lib/document.js +58 -72
- package/lib/drivers/node-mongodb-native/collection.js +12 -4
- package/lib/drivers/node-mongodb-native/connection.js +11 -0
- package/lib/error/cast.js +3 -2
- package/lib/helpers/clone.js +11 -2
- package/lib/helpers/cursor/eachAsync.js +18 -15
- package/lib/helpers/document/cleanModifiedSubpaths.js +1 -0
- package/lib/helpers/document/compile.js +7 -4
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +14 -0
- package/lib/helpers/indexes/getRelatedIndexes.js +59 -0
- package/lib/helpers/isAsyncFunction.js +6 -7
- package/lib/helpers/populate/assignVals.js +4 -0
- package/lib/helpers/printJestWarning.js +2 -2
- package/lib/helpers/projection/applyProjection.js +77 -0
- package/lib/helpers/projection/hasIncludedChildren.js +36 -0
- package/lib/helpers/projection/isExclusive.js +5 -2
- package/lib/helpers/projection/isInclusive.js +5 -1
- package/lib/helpers/query/cast$expr.js +14 -19
- package/lib/helpers/query/hasDollarKeys.js +7 -3
- package/lib/helpers/query/isOperator.js +5 -2
- package/lib/helpers/schema/getIndexes.js +6 -2
- package/lib/index.js +14 -17
- package/lib/internal.js +9 -1
- package/lib/model.js +159 -153
- package/lib/options/SchemaTypeOptions.js +1 -1
- package/lib/plugins/trackTransaction.js +1 -1
- package/lib/query.js +159 -147
- package/lib/queryhelpers.js +8 -28
- package/lib/schema/SubdocumentPath.js +5 -4
- package/lib/schema/array.js +13 -6
- package/lib/schema/buffer.js +1 -1
- package/lib/schema/date.js +1 -1
- package/lib/schema/decimal128.js +1 -1
- package/lib/schema/documentarray.js +9 -7
- package/lib/schema/number.js +1 -1
- package/lib/schema/objectid.js +1 -1
- package/lib/schema/string.js +4 -4
- package/lib/schema.js +12 -8
- package/lib/schematype.js +12 -14
- package/lib/types/ArraySubdocument.js +1 -1
- package/lib/types/DocumentArray/index.js +1 -1
- package/lib/types/array/index.js +2 -2
- package/lib/types/array/methods/index.js +10 -11
- package/lib/types/buffer.js +3 -3
- package/lib/types/map.js +3 -4
- package/lib/utils.js +9 -3
- package/package.json +17 -21
- package/tsconfig.json +0 -2
- package/types/Connection.d.ts +212 -0
- package/types/Error.d.ts +129 -0
- package/types/PipelineStage.d.ts +272 -0
- package/types/index.d.ts +61 -602
- package/lib/types/array/ArrayWrapper.js +0 -981
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
declare module 'mongoose' {
|
|
2
|
+
/**
|
|
3
|
+
* [Stages reference](https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/#aggregation-pipeline-stages)
|
|
4
|
+
*/
|
|
5
|
+
export type PipelineStage =
|
|
6
|
+
| PipelineStage.AddFields
|
|
7
|
+
| PipelineStage.Bucket
|
|
8
|
+
| PipelineStage.BucketAuto
|
|
9
|
+
| PipelineStage.CollStats
|
|
10
|
+
| PipelineStage.Count
|
|
11
|
+
| PipelineStage.Facet
|
|
12
|
+
| PipelineStage.GeoNear
|
|
13
|
+
| PipelineStage.GraphLookup
|
|
14
|
+
| PipelineStage.Group
|
|
15
|
+
| PipelineStage.IndexStats
|
|
16
|
+
| PipelineStage.Limit
|
|
17
|
+
| PipelineStage.ListSessions
|
|
18
|
+
| PipelineStage.Lookup
|
|
19
|
+
| PipelineStage.Match
|
|
20
|
+
| PipelineStage.Merge
|
|
21
|
+
| PipelineStage.Out
|
|
22
|
+
| PipelineStage.PlanCacheStats
|
|
23
|
+
| PipelineStage.Project
|
|
24
|
+
| PipelineStage.Redact
|
|
25
|
+
| PipelineStage.ReplaceRoot
|
|
26
|
+
| PipelineStage.ReplaceWith
|
|
27
|
+
| PipelineStage.Sample
|
|
28
|
+
| PipelineStage.Search
|
|
29
|
+
| PipelineStage.Set
|
|
30
|
+
| PipelineStage.SetWindowFields
|
|
31
|
+
| PipelineStage.Skip
|
|
32
|
+
| PipelineStage.Sort
|
|
33
|
+
| PipelineStage.SortByCount
|
|
34
|
+
| PipelineStage.UnionWith
|
|
35
|
+
| PipelineStage.Unset
|
|
36
|
+
| PipelineStage.Unwind
|
|
37
|
+
|
|
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
|
+
|
|
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 }>
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
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'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
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?: {}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface Count {
|
|
75
|
+
/** [`$count` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/count/) */
|
|
76
|
+
$count: string
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface Facet {
|
|
80
|
+
/** [`$facet` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/facet/) */
|
|
81
|
+
$facet: Record<string, FacetPipelineStage[]>
|
|
82
|
+
}
|
|
83
|
+
|
|
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
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
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
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
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
|
+
|
|
121
|
+
export interface IndexStats {
|
|
122
|
+
/** [`$indexStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/) */
|
|
123
|
+
$indexStats: {}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface Limit {
|
|
127
|
+
/** [`$limit` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/limit/) */
|
|
128
|
+
$limit: number
|
|
129
|
+
}
|
|
130
|
+
|
|
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
|
+
|
|
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>[]
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface Match {
|
|
149
|
+
/** [`$match` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) */
|
|
150
|
+
$match: AnyObject
|
|
151
|
+
}
|
|
152
|
+
|
|
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'
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
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
|
+
|
|
169
|
+
export interface PlanCacheStats {
|
|
170
|
+
/** [`$planCacheStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/planCacheStats/) */
|
|
171
|
+
$planCacheStats: {}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface Project {
|
|
175
|
+
/** [`$project` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/project/) */
|
|
176
|
+
$project: { [field: string]: any }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface Redact {
|
|
180
|
+
/** [`$redact` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/redact/) */
|
|
181
|
+
$redact: any
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface ReplaceRoot {
|
|
185
|
+
/** [`$replaceRoot` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceRoot/) */
|
|
186
|
+
$replaceRoot: { newRoot: any }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface ReplaceWith {
|
|
190
|
+
/** [`$replaceWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/) */
|
|
191
|
+
$replaceWith: any
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface Sample {
|
|
195
|
+
/** [`$sample` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sample/) */
|
|
196
|
+
$sample: { size: number }
|
|
197
|
+
}
|
|
198
|
+
|
|
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
|
+
/** [`highlightPath` reference](https://docs.atlas.mongodb.com/atlas-search/path-construction/#multiple-field-search) */
|
|
205
|
+
path: string | string[] | { value: string, multi: string};
|
|
206
|
+
maxCharsToExamine?: number;
|
|
207
|
+
maxNumPassages?: number;
|
|
208
|
+
};
|
|
209
|
+
[key: string]: any;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface Set {
|
|
214
|
+
/** [`$set` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/set/) */
|
|
215
|
+
$set: Record<string, any>
|
|
216
|
+
}
|
|
217
|
+
|
|
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
|
+
}
|
|
231
|
+
}
|
|
232
|
+
>
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface Skip {
|
|
237
|
+
/** [`$skip` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/skip/) */
|
|
238
|
+
$skip: number
|
|
239
|
+
}
|
|
240
|
+
|
|
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
|
+
|
|
246
|
+
export interface SortByCount {
|
|
247
|
+
/** [`$sortByCount` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sortByCount/) */
|
|
248
|
+
$sortByCount: any
|
|
249
|
+
}
|
|
250
|
+
|
|
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
|
+
|
|
258
|
+
export interface Unset {
|
|
259
|
+
/** [`$unset` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unset/) */
|
|
260
|
+
$unset: string | string[]
|
|
261
|
+
}
|
|
262
|
+
|
|
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
|
+
|
|
268
|
+
type AccumulatorOperator = '$accumulator' | '$addToSet' | '$avg' | '$count' | '$first' | '$last' | '$max' | '$mergeObjects' | '$min' | '$push' | '$stdDevPop' | '$stdDevSamp' | '$sum'
|
|
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
|
+
}
|
|
272
|
+
}
|