mongoose 6.3.4 → 6.3.7
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 +1 -1
- package/dist/browser.umd.js +1 -1
- package/lgtm.yml +12 -0
- package/lib/cast/objectid.js +3 -2
- package/lib/connection.js +3 -2
- package/lib/document.js +37 -24
- package/lib/error/index.js +2 -2
- package/lib/helpers/clone.js +7 -1
- package/lib/helpers/common.js +3 -4
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +2 -2
- package/lib/helpers/isBsonType.js +5 -3
- package/lib/helpers/path/setDottedPath.js +14 -1
- package/lib/helpers/schematype/handleImmutable.js +2 -1
- package/lib/helpers/topology/isAtlas.js +15 -2
- package/lib/helpers/update/applyTimestampsToChildren.js +4 -0
- package/lib/helpers/update/castArrayFilters.js +3 -0
- package/lib/index.js +4 -3
- package/lib/options/SchemaTypeOptions.js +13 -0
- package/lib/query.js +4 -1
- package/lib/schema/SubdocumentPath.js +8 -1
- package/lib/schema/decimal128.js +4 -4
- package/lib/schema/documentarray.js +2 -4
- package/lib/schema/map.js +8 -0
- package/lib/schema/objectid.js +4 -3
- package/lib/schema/string.js +2 -2
- package/lib/schema.js +33 -2
- package/lib/schematype.js +1 -0
- package/lib/types/DocumentArray/methods/index.js +3 -3
- package/lib/types/array/methods/index.js +3 -3
- package/lib/types/map.js +4 -4
- package/lib/utils.js +3 -4
- package/package.json +17 -15
- package/types/aggregate.d.ts +3 -4
- package/types/callback.d.ts +8 -0
- package/types/collection.d.ts +46 -0
- package/types/connection.d.ts +91 -71
- package/types/document.d.ts +1 -1
- package/types/error.d.ts +5 -1
- package/types/helpers.d.ts +32 -0
- package/types/index.d.ts +32 -1859
- package/types/indizes.d.ts +98 -0
- package/types/middlewares.d.ts +14 -0
- package/types/models.d.ts +419 -0
- package/types/populate.d.ts +40 -0
- package/types/query.d.ts +637 -0
- package/types/schematypes.d.ts +427 -0
- package/types/session.d.ts +36 -0
- package/types/types.d.ts +102 -0
- package/types/utility.d.ts +13 -0
- package/types/validation.d.ts +32 -0
- package/.lgtm.yml +0 -3
- package/CHANGELOG.md +0 -7300
- package/History.md +0 -1
package/types/query.d.ts
ADDED
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
declare module 'mongoose' {
|
|
2
|
+
import mongodb = require('mongodb');
|
|
3
|
+
|
|
4
|
+
type ApplyBasicQueryCasting<T> = T | T[] | any;
|
|
5
|
+
type Condition<T> = ApplyBasicQueryCasting<T> | QuerySelector<ApplyBasicQueryCasting<T>>;
|
|
6
|
+
|
|
7
|
+
type _FilterQuery<T> = {
|
|
8
|
+
[P in keyof T]?: Condition<T[P]>;
|
|
9
|
+
} & RootQuerySelector<T>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Filter query to select the documents that match the query
|
|
13
|
+
* @example
|
|
14
|
+
* ```js
|
|
15
|
+
* { age: { $gte: 30 } }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
type FilterQuery<T> = _FilterQuery<T>;
|
|
19
|
+
|
|
20
|
+
type MongooseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, 'populate' | 'lean' | 'strict' | 'sanitizeProjection' | 'sanitizeFilter'>;
|
|
21
|
+
|
|
22
|
+
type ProjectionFields<DocType> = { [Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any } & Record<string, any>;
|
|
23
|
+
|
|
24
|
+
type QueryWithHelpers<ResultType, DocType, THelpers = {}, RawDocType = DocType> = Query<ResultType, DocType, THelpers, RawDocType> & THelpers;
|
|
25
|
+
|
|
26
|
+
type QuerySelector<T> = {
|
|
27
|
+
// Comparison
|
|
28
|
+
$eq?: T;
|
|
29
|
+
$gt?: T;
|
|
30
|
+
$gte?: T;
|
|
31
|
+
$in?: [T] extends AnyArray<any> ? Unpacked<T>[] : T[];
|
|
32
|
+
$lt?: T;
|
|
33
|
+
$lte?: T;
|
|
34
|
+
$ne?: T;
|
|
35
|
+
$nin?: [T] extends AnyArray<any> ? Unpacked<T>[] : T[];
|
|
36
|
+
// Logical
|
|
37
|
+
$not?: T extends string ? QuerySelector<T> | RegExp : QuerySelector<T>;
|
|
38
|
+
// Element
|
|
39
|
+
/**
|
|
40
|
+
* When `true`, `$exists` matches the documents that contain the field,
|
|
41
|
+
* including documents where the field value is null.
|
|
42
|
+
*/
|
|
43
|
+
$exists?: boolean;
|
|
44
|
+
$type?: string | number;
|
|
45
|
+
// Evaluation
|
|
46
|
+
$expr?: any;
|
|
47
|
+
$jsonSchema?: any;
|
|
48
|
+
$mod?: T extends number ? [number, number] : never;
|
|
49
|
+
$regex?: T extends string ? RegExp | string : never;
|
|
50
|
+
$options?: T extends string ? string : never;
|
|
51
|
+
// Geospatial
|
|
52
|
+
// TODO: define better types for geo queries
|
|
53
|
+
$geoIntersects?: { $geometry: object };
|
|
54
|
+
$geoWithin?: object;
|
|
55
|
+
$near?: object;
|
|
56
|
+
$nearSphere?: object;
|
|
57
|
+
$maxDistance?: number;
|
|
58
|
+
// Array
|
|
59
|
+
// TODO: define better types for $all and $elemMatch
|
|
60
|
+
$all?: T extends AnyArray<any> ? any[] : never;
|
|
61
|
+
$elemMatch?: T extends AnyArray<any> ? object : never;
|
|
62
|
+
$size?: T extends AnyArray<any> ? number : never;
|
|
63
|
+
// Bitwise
|
|
64
|
+
$bitsAllClear?: number | mongodb.Binary | number[];
|
|
65
|
+
$bitsAllSet?: number | mongodb.Binary | number[];
|
|
66
|
+
$bitsAnyClear?: number | mongodb.Binary | number[];
|
|
67
|
+
$bitsAnySet?: number | mongodb.Binary | number[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type RootQuerySelector<T> = {
|
|
71
|
+
/** @see https://docs.mongodb.com/manual/reference/operator/query/and/#op._S_and */
|
|
72
|
+
$and?: Array<FilterQuery<T>>;
|
|
73
|
+
/** @see https://docs.mongodb.com/manual/reference/operator/query/nor/#op._S_nor */
|
|
74
|
+
$nor?: Array<FilterQuery<T>>;
|
|
75
|
+
/** @see https://docs.mongodb.com/manual/reference/operator/query/or/#op._S_or */
|
|
76
|
+
$or?: Array<FilterQuery<T>>;
|
|
77
|
+
/** @see https://docs.mongodb.com/manual/reference/operator/query/text */
|
|
78
|
+
$text?: {
|
|
79
|
+
$search: string;
|
|
80
|
+
$language?: string;
|
|
81
|
+
$caseSensitive?: boolean;
|
|
82
|
+
$diacriticSensitive?: boolean;
|
|
83
|
+
};
|
|
84
|
+
/** @see https://docs.mongodb.com/manual/reference/operator/query/where/#op._S_where */
|
|
85
|
+
$where?: string | Function;
|
|
86
|
+
/** @see https://docs.mongodb.com/manual/reference/operator/query/comment/#op._S_comment */
|
|
87
|
+
$comment?: string;
|
|
88
|
+
// we could not find a proper TypeScript generic to support nested queries e.g. 'user.friends.name'
|
|
89
|
+
// this will mark all unrecognized properties as any (including nested queries)
|
|
90
|
+
[key: string]: any;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
interface QueryOptions<DocType = unknown> extends
|
|
94
|
+
PopulateOption,
|
|
95
|
+
SessionOption {
|
|
96
|
+
arrayFilters?: { [key: string]: any }[];
|
|
97
|
+
batchSize?: number;
|
|
98
|
+
collation?: mongodb.CollationOptions;
|
|
99
|
+
comment?: any;
|
|
100
|
+
context?: string;
|
|
101
|
+
explain?: mongodb.ExplainVerbosityLike;
|
|
102
|
+
fields?: any | string;
|
|
103
|
+
hint?: mongodb.Hint;
|
|
104
|
+
/**
|
|
105
|
+
* If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.
|
|
106
|
+
*/
|
|
107
|
+
lean?: boolean | any;
|
|
108
|
+
limit?: number;
|
|
109
|
+
maxTimeMS?: number;
|
|
110
|
+
maxscan?: number;
|
|
111
|
+
multi?: boolean;
|
|
112
|
+
multipleCastError?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* By default, `findOneAndUpdate()` returns the document as it was **before**
|
|
115
|
+
* `update` was applied. If you set `new: true`, `findOneAndUpdate()` will
|
|
116
|
+
* instead give you the object after `update` was applied.
|
|
117
|
+
*/
|
|
118
|
+
new?: boolean;
|
|
119
|
+
overwrite?: boolean;
|
|
120
|
+
overwriteDiscriminatorKey?: boolean;
|
|
121
|
+
projection?: ProjectionType<DocType>;
|
|
122
|
+
/**
|
|
123
|
+
* if true, returns the raw result from the MongoDB driver
|
|
124
|
+
*/
|
|
125
|
+
rawResult?: boolean;
|
|
126
|
+
readPreference?: string | mongodb.ReadPreferenceMode;
|
|
127
|
+
/**
|
|
128
|
+
* An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`.
|
|
129
|
+
*/
|
|
130
|
+
returnOriginal?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Another alias for the `new` option. `returnOriginal` is deprecated so this should be used.
|
|
133
|
+
*/
|
|
134
|
+
returnDocument?: string;
|
|
135
|
+
runValidators?: boolean;
|
|
136
|
+
/* Set to `true` to automatically sanitize potentially unsafe user-generated query projections */
|
|
137
|
+
sanitizeProjection?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Set to `true` to automatically sanitize potentially unsafe query filters by stripping out query selectors that
|
|
140
|
+
* aren't explicitly allowed using `mongoose.trusted()`.
|
|
141
|
+
*/
|
|
142
|
+
sanitizeFilter?: boolean;
|
|
143
|
+
setDefaultsOnInsert?: boolean;
|
|
144
|
+
skip?: number;
|
|
145
|
+
snapshot?: any;
|
|
146
|
+
sort?: any;
|
|
147
|
+
/** overwrites the schema's strict mode option */
|
|
148
|
+
strict?: boolean | string;
|
|
149
|
+
/**
|
|
150
|
+
* equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default
|
|
151
|
+
* [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
|
|
152
|
+
*/
|
|
153
|
+
strictQuery?: boolean | 'throw';
|
|
154
|
+
tailable?: number;
|
|
155
|
+
/**
|
|
156
|
+
* If set to `false` and schema-level timestamps are enabled,
|
|
157
|
+
* skip timestamps for this update. Note that this allows you to overwrite
|
|
158
|
+
* timestamps. Does nothing if schema-level timestamps are not set.
|
|
159
|
+
*/
|
|
160
|
+
timestamps?: boolean;
|
|
161
|
+
upsert?: boolean;
|
|
162
|
+
writeConcern?: mongodb.WriteConcern;
|
|
163
|
+
|
|
164
|
+
[other: string]: any;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> implements SessionOperation {
|
|
168
|
+
_mongooseOptions: MongooseQueryOptions<DocType>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Returns a wrapper around a [mongodb driver cursor](http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html).
|
|
172
|
+
* A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
|
|
173
|
+
* This is equivalent to calling `.cursor()` with no arguments.
|
|
174
|
+
*/
|
|
175
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<DocType>;
|
|
176
|
+
|
|
177
|
+
/** Executes the query */
|
|
178
|
+
exec(callback: Callback<ResultType>): void;
|
|
179
|
+
exec(): Promise<ResultType>;
|
|
180
|
+
|
|
181
|
+
$where(argument: string | Function): QueryWithHelpers<DocType[], DocType, THelpers, RawDocType>;
|
|
182
|
+
|
|
183
|
+
/** Specifies an `$all` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
184
|
+
all(path: string, val: Array<any>): this;
|
|
185
|
+
all(val: Array<any>): this;
|
|
186
|
+
|
|
187
|
+
/** Sets the allowDiskUse option for the query (ignored for < 4.4.0) */
|
|
188
|
+
allowDiskUse(value: boolean): this;
|
|
189
|
+
|
|
190
|
+
/** Specifies arguments for an `$and` condition. */
|
|
191
|
+
and(array: FilterQuery<DocType>[]): this;
|
|
192
|
+
|
|
193
|
+
/** Specifies the batchSize option. */
|
|
194
|
+
batchSize(val: number): this;
|
|
195
|
+
|
|
196
|
+
/** Specifies a `$box` condition */
|
|
197
|
+
box(lower: number[], upper: number[]): this;
|
|
198
|
+
box(val: any): this;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Casts this query to the schema of `model`.
|
|
202
|
+
*
|
|
203
|
+
* @param {Model} [model] the model to cast to. If not set, defaults to `this.model`
|
|
204
|
+
* @param {Object} [obj] If not set, defaults to this query's conditions
|
|
205
|
+
* @return {Object} the casted `obj`
|
|
206
|
+
*/
|
|
207
|
+
cast(model?: Model<any, THelpers> | null, obj?: any): any;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Executes the query returning a `Promise` which will be
|
|
211
|
+
* resolved with either the doc(s) or rejected with the error.
|
|
212
|
+
* Like `.then()`, but only takes a rejection handler.
|
|
213
|
+
*/
|
|
214
|
+
catch: Promise<ResultType>['catch'];
|
|
215
|
+
|
|
216
|
+
/** Specifies a `$center` or `$centerSphere` condition. */
|
|
217
|
+
circle(path: string, area: any): this;
|
|
218
|
+
circle(area: any): this;
|
|
219
|
+
|
|
220
|
+
/** Make a copy of this query so you can re-execute it. */
|
|
221
|
+
clone(): this;
|
|
222
|
+
|
|
223
|
+
/** Adds a collation to this op (MongoDB 3.4 and up) */
|
|
224
|
+
collation(value: mongodb.CollationOptions): this;
|
|
225
|
+
|
|
226
|
+
/** Specifies the `comment` option. */
|
|
227
|
+
comment(val: string): this;
|
|
228
|
+
|
|
229
|
+
/** Specifies this query as a `count` query. */
|
|
230
|
+
count(criteria: FilterQuery<DocType>, callback?: Callback<number>): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
231
|
+
count(callback?: Callback<number>): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
232
|
+
|
|
233
|
+
/** Specifies this query as a `countDocuments` query. */
|
|
234
|
+
countDocuments(
|
|
235
|
+
criteria: FilterQuery<DocType>,
|
|
236
|
+
options?: QueryOptions<DocType>,
|
|
237
|
+
callback?: Callback<number>
|
|
238
|
+
): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
239
|
+
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Returns a wrapper around a [mongodb driver cursor](http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html).
|
|
243
|
+
* A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
|
|
244
|
+
*/
|
|
245
|
+
cursor(options?: QueryOptions<DocType>): Cursor<DocType, QueryOptions<DocType>>;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Declare and/or execute this query as a `deleteMany()` operation. Works like
|
|
249
|
+
* remove, except it deletes _every_ document that matches `filter` in the
|
|
250
|
+
* collection, regardless of the value of `single`.
|
|
251
|
+
*/
|
|
252
|
+
deleteMany(filter?: FilterQuery<DocType>, options?: QueryOptions<DocType>, callback?: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
253
|
+
deleteMany(filter: FilterQuery<DocType>, callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
254
|
+
deleteMany(callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Declare and/or execute this query as a `deleteOne()` operation. Works like
|
|
258
|
+
* remove, except it deletes at most one document regardless of the `single`
|
|
259
|
+
* option.
|
|
260
|
+
*/
|
|
261
|
+
deleteOne(filter?: FilterQuery<DocType>, options?: QueryOptions<DocType>, callback?: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
262
|
+
deleteOne(filter: FilterQuery<DocType>, callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
263
|
+
deleteOne(callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
264
|
+
|
|
265
|
+
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
|
|
266
|
+
distinct<ReturnType = any>(field: string, filter?: FilterQuery<DocType>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, DocType, THelpers, RawDocType>;
|
|
267
|
+
|
|
268
|
+
/** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
269
|
+
elemMatch<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$elemMatch']): this;
|
|
270
|
+
elemMatch(val: Function | any): this;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Gets/sets the error flag on this query. If this flag is not null or
|
|
274
|
+
* undefined, the `exec()` promise will reject without executing.
|
|
275
|
+
*/
|
|
276
|
+
error(): NativeError | null;
|
|
277
|
+
error(val: NativeError | null): this;
|
|
278
|
+
|
|
279
|
+
/** Specifies the complementary comparison value for paths specified with `where()` */
|
|
280
|
+
equals(val: any): this;
|
|
281
|
+
|
|
282
|
+
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
|
|
283
|
+
estimatedDocumentCount(options?: QueryOptions<DocType>, callback?: Callback<number>): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
284
|
+
|
|
285
|
+
/** Specifies a `$exists` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
286
|
+
exists<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$exists']): this;
|
|
287
|
+
exists(val: boolean): this;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Sets the [`explain` option](https://docs.mongodb.com/manual/reference/method/cursor.explain/),
|
|
291
|
+
* which makes this query return detailed execution stats instead of the actual
|
|
292
|
+
* query result. This method is useful for determining what index your queries
|
|
293
|
+
* use.
|
|
294
|
+
*/
|
|
295
|
+
explain(verbose?: mongodb.ExplainVerbosityLike): this;
|
|
296
|
+
|
|
297
|
+
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
298
|
+
find(
|
|
299
|
+
filter: FilterQuery<DocType>,
|
|
300
|
+
projection?: ProjectionType<DocType> | null,
|
|
301
|
+
options?: QueryOptions<DocType> | null,
|
|
302
|
+
callback?: Callback<DocType[]>
|
|
303
|
+
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType>;
|
|
304
|
+
find(
|
|
305
|
+
filter: FilterQuery<DocType>,
|
|
306
|
+
projection?: ProjectionType<DocType> | null,
|
|
307
|
+
callback?: Callback<DocType[]>
|
|
308
|
+
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType>;
|
|
309
|
+
find(
|
|
310
|
+
filter: FilterQuery<DocType>,
|
|
311
|
+
callback?: Callback<DocType[]>
|
|
312
|
+
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType>;
|
|
313
|
+
find(callback?: Callback<DocType[]>): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType>;
|
|
314
|
+
|
|
315
|
+
/** Declares the query a findOne operation. When executed, the first found document is passed to the callback. */
|
|
316
|
+
findOne(
|
|
317
|
+
filter?: FilterQuery<DocType>,
|
|
318
|
+
projection?: ProjectionType<DocType> | null,
|
|
319
|
+
options?: QueryOptions<DocType> | null,
|
|
320
|
+
callback?: Callback<DocType | null>
|
|
321
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
322
|
+
findOne(
|
|
323
|
+
filter?: FilterQuery<DocType>,
|
|
324
|
+
projection?: ProjectionType<DocType> | null,
|
|
325
|
+
callback?: Callback<DocType | null>
|
|
326
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
327
|
+
findOne(
|
|
328
|
+
filter?: FilterQuery<DocType>,
|
|
329
|
+
callback?: Callback<DocType | null>
|
|
330
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
331
|
+
|
|
332
|
+
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
333
|
+
findOneAndDelete(
|
|
334
|
+
filter?: FilterQuery<DocType>,
|
|
335
|
+
options?: QueryOptions<DocType> | null,
|
|
336
|
+
callback?: (err: CallbackError, doc: DocType | null, res: any) => void
|
|
337
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
338
|
+
|
|
339
|
+
/** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
|
|
340
|
+
findOneAndRemove(
|
|
341
|
+
filter?: FilterQuery<DocType>,
|
|
342
|
+
options?: QueryOptions<DocType> | null,
|
|
343
|
+
callback?: (err: CallbackError, doc: DocType | null, res: any) => void
|
|
344
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
345
|
+
|
|
346
|
+
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
347
|
+
findOneAndUpdate(
|
|
348
|
+
filter: FilterQuery<DocType>,
|
|
349
|
+
update: UpdateQuery<DocType>,
|
|
350
|
+
options: QueryOptions<DocType> & { rawResult: true },
|
|
351
|
+
callback?: (err: CallbackError, doc: DocType | null, res: ModifyResult<DocType>) => void
|
|
352
|
+
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType>;
|
|
353
|
+
findOneAndUpdate(
|
|
354
|
+
filter: FilterQuery<DocType>,
|
|
355
|
+
update: UpdateQuery<DocType>,
|
|
356
|
+
options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc,
|
|
357
|
+
callback?: (err: CallbackError, doc: DocType, res: ModifyResult<DocType>) => void
|
|
358
|
+
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType>;
|
|
359
|
+
findOneAndUpdate(
|
|
360
|
+
filter?: FilterQuery<DocType>,
|
|
361
|
+
update?: UpdateQuery<DocType>,
|
|
362
|
+
options?: QueryOptions<DocType> | null,
|
|
363
|
+
callback?: (err: CallbackError, doc: DocType | null, res: ModifyResult<DocType>) => void
|
|
364
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
365
|
+
|
|
366
|
+
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
367
|
+
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions<DocType> | null, callback?: (err: CallbackError, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
368
|
+
|
|
369
|
+
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
370
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions<DocType> & { rawResult: true }, callback?: (err: CallbackError, doc: any, res?: any) => void): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
371
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: DocType, res?: any) => void): QueryWithHelpers<DocType, DocType, THelpers, RawDocType>;
|
|
372
|
+
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<DocType>, options?: QueryOptions<DocType> | null, callback?: (CallbackError: any, doc: DocType | null, res?: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
373
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, callback: (CallbackError: any, doc: DocType | null, res?: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
374
|
+
|
|
375
|
+
/** Specifies a `$geometry` condition */
|
|
376
|
+
geometry(object: { type: string, coordinates: any[] }): this;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* For update operations, returns the value of a path in the update's `$set`.
|
|
380
|
+
* Useful for writing getters/setters that can work with both update operations
|
|
381
|
+
* and `save()`.
|
|
382
|
+
*/
|
|
383
|
+
get(path: string): any;
|
|
384
|
+
|
|
385
|
+
/** Returns the current query filter (also known as conditions) as a POJO. */
|
|
386
|
+
getFilter(): FilterQuery<DocType>;
|
|
387
|
+
|
|
388
|
+
/** Gets query options. */
|
|
389
|
+
getOptions(): QueryOptions<DocType>;
|
|
390
|
+
|
|
391
|
+
/** Gets a list of paths to be populated by this query */
|
|
392
|
+
getPopulatedPaths(): Array<string>;
|
|
393
|
+
|
|
394
|
+
/** Returns the current query filter. Equivalent to `getFilter()`. */
|
|
395
|
+
getQuery(): FilterQuery<DocType>;
|
|
396
|
+
|
|
397
|
+
/** Returns the current update operations as a JSON object. */
|
|
398
|
+
getUpdate(): UpdateQuery<DocType> | UpdateWithAggregationPipeline | null;
|
|
399
|
+
|
|
400
|
+
/** Specifies a `$gt` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
401
|
+
gt<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$gt']): this;
|
|
402
|
+
gt(val: number): this;
|
|
403
|
+
|
|
404
|
+
/** Specifies a `$gte` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
405
|
+
gte<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$gte']): this;
|
|
406
|
+
gte(val: number): this;
|
|
407
|
+
|
|
408
|
+
/** Sets query hints. */
|
|
409
|
+
hint(val: any): this;
|
|
410
|
+
|
|
411
|
+
/** Specifies an `$in` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
412
|
+
in<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$in']): this;
|
|
413
|
+
in(val: Array<any>): this;
|
|
414
|
+
|
|
415
|
+
/** Declares an intersects query for `geometry()`. */
|
|
416
|
+
intersects(arg?: any): this;
|
|
417
|
+
|
|
418
|
+
/** Requests acknowledgement that this operation has been persisted to MongoDB's on-disk journal. */
|
|
419
|
+
j(val: boolean | null): this;
|
|
420
|
+
|
|
421
|
+
/** Sets the lean option. */
|
|
422
|
+
lean<LeanResultType = RawDocType extends Document ? LeanDocumentOrArray<ResultType> : LeanDocumentOrArrayWithRawType<ResultType, Require_id<RawDocType>>>(val?: boolean | any): QueryWithHelpers<LeanResultType, DocType, THelpers, RawDocType>;
|
|
423
|
+
|
|
424
|
+
/** Specifies the maximum number of documents the query will return. */
|
|
425
|
+
limit(val: number): this;
|
|
426
|
+
|
|
427
|
+
/** Specifies a `$lt` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
428
|
+
lt<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$lt']): this;
|
|
429
|
+
lt(val: number): this;
|
|
430
|
+
|
|
431
|
+
/** Specifies a `$lte` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
432
|
+
lte<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$lte']): this;
|
|
433
|
+
lte(val: number): this;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Runs a function `fn` and treats the return value of `fn` as the new value
|
|
437
|
+
* for the query to resolve to.
|
|
438
|
+
*/
|
|
439
|
+
transform<MappedType>(fn: (doc: ResultType) => MappedType): QueryWithHelpers<MappedType, DocType, THelpers, RawDocType>;
|
|
440
|
+
|
|
441
|
+
/** Specifies an `$maxDistance` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
442
|
+
maxDistance(path: string, val: number): this;
|
|
443
|
+
maxDistance(val: number): this;
|
|
444
|
+
|
|
445
|
+
/** Specifies the maxScan option. */
|
|
446
|
+
maxScan(val: number): this;
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Sets the [maxTimeMS](https://docs.mongodb.com/manual/reference/method/cursor.maxTimeMS/)
|
|
450
|
+
* option. This will tell the MongoDB server to abort if the query or write op
|
|
451
|
+
* has been running for more than `ms` milliseconds.
|
|
452
|
+
*/
|
|
453
|
+
maxTimeMS(ms: number): this;
|
|
454
|
+
|
|
455
|
+
/** Merges another Query or conditions object into this one. */
|
|
456
|
+
merge(source: Query<any, any> | FilterQuery<DocType>): this;
|
|
457
|
+
|
|
458
|
+
/** Specifies a `$mod` condition, filters documents for documents whose `path` property is a number that is equal to `remainder` modulo `divisor`. */
|
|
459
|
+
mod<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$mod']): this;
|
|
460
|
+
mod(val: Array<number>): this;
|
|
461
|
+
|
|
462
|
+
/** The model this query was created from */
|
|
463
|
+
model: typeof Model;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Getter/setter around the current mongoose-specific options for this query
|
|
467
|
+
* Below are the current Mongoose-specific options.
|
|
468
|
+
*/
|
|
469
|
+
mongooseOptions(val?: MongooseQueryOptions): MongooseQueryOptions;
|
|
470
|
+
|
|
471
|
+
/** Specifies a `$ne` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
472
|
+
ne<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$ne']): this;
|
|
473
|
+
ne(val: any): this;
|
|
474
|
+
|
|
475
|
+
/** Specifies a `$near` or `$nearSphere` condition */
|
|
476
|
+
near<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$near']): this;
|
|
477
|
+
near(val: any): this;
|
|
478
|
+
|
|
479
|
+
/** Specifies an `$nin` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
480
|
+
nin<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$nin']): this;
|
|
481
|
+
nin(val: Array<any>): this;
|
|
482
|
+
|
|
483
|
+
/** Specifies arguments for an `$nor` condition. */
|
|
484
|
+
nor(array: Array<FilterQuery<DocType>>): this;
|
|
485
|
+
|
|
486
|
+
/** Specifies arguments for an `$or` condition. */
|
|
487
|
+
or(array: Array<FilterQuery<DocType>>): this;
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Make this query throw an error if no documents match the given `filter`.
|
|
491
|
+
* This is handy for integrating with async/await, because `orFail()` saves you
|
|
492
|
+
* an extra `if` statement to check if no document was found.
|
|
493
|
+
*/
|
|
494
|
+
orFail(err?: NativeError | (() => NativeError)): QueryWithHelpers<NonNullable<ResultType>, DocType, THelpers, RawDocType>;
|
|
495
|
+
|
|
496
|
+
/** Specifies a `$polygon` condition */
|
|
497
|
+
polygon(path: string, ...coordinatePairs: number[][]): this;
|
|
498
|
+
polygon(...coordinatePairs: number[][]): this;
|
|
499
|
+
|
|
500
|
+
/** Specifies paths which should be populated with other documents. */
|
|
501
|
+
populate<Paths = {}>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, UnpackedIntersection<RawDocType, Paths>>;
|
|
502
|
+
populate<Paths = {}>(options: PopulateOptions | (PopulateOptions | string)[]): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, UnpackedIntersection<RawDocType, Paths>>;
|
|
503
|
+
|
|
504
|
+
/** Get/set the current projection (AKA fields). Pass `null` to remove the current projection. */
|
|
505
|
+
projection(fields?: ProjectionFields<DocType> | string): ProjectionFields<DocType>;
|
|
506
|
+
projection(fields: null): null;
|
|
507
|
+
projection(): ProjectionFields<DocType> | null;
|
|
508
|
+
|
|
509
|
+
/** Determines the MongoDB nodes from which to read. */
|
|
510
|
+
read(pref: string | mongodb.ReadPreferenceMode, tags?: any[]): this;
|
|
511
|
+
|
|
512
|
+
/** Sets the readConcern option for the query. */
|
|
513
|
+
readConcern(level: string): this;
|
|
514
|
+
|
|
515
|
+
/** Specifies a `$regex` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
516
|
+
regex<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$regex']): this;
|
|
517
|
+
regex(val: string | RegExp): this;
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Declare and/or execute this query as a remove() operation. `remove()` is
|
|
521
|
+
* deprecated, you should use [`deleteOne()`](#query_Query-deleteOne)
|
|
522
|
+
* or [`deleteMany()`](#query_Query-deleteMany) instead.
|
|
523
|
+
*/
|
|
524
|
+
remove(filter?: FilterQuery<DocType>, callback?: Callback<mongodb.UpdateResult>): Query<mongodb.UpdateResult, DocType, THelpers, RawDocType>;
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Declare and/or execute this query as a replaceOne() operation. Same as
|
|
528
|
+
* `update()`, except MongoDB will replace the existing document and will
|
|
529
|
+
* not accept any [atomic](https://docs.mongodb.com/manual/tutorial/model-data-for-atomic-operations/#pattern) operators (`$set`, etc.)
|
|
530
|
+
*/
|
|
531
|
+
replaceOne(filter?: FilterQuery<DocType>, replacement?: DocType | AnyObject, options?: QueryOptions<DocType> | null, callback?: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
532
|
+
|
|
533
|
+
/** Specifies which document fields to include or exclude (also known as the query "projection") */
|
|
534
|
+
select(arg: string | any): this;
|
|
535
|
+
|
|
536
|
+
/** Determines if field selection has been made. */
|
|
537
|
+
selected(): boolean;
|
|
538
|
+
|
|
539
|
+
/** Determines if exclusive field selection has been made. */
|
|
540
|
+
selectedExclusively(): boolean;
|
|
541
|
+
|
|
542
|
+
/** Determines if inclusive field selection has been made. */
|
|
543
|
+
selectedInclusively(): boolean;
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Sets the [MongoDB session](https://docs.mongodb.com/manual/reference/server-sessions/)
|
|
547
|
+
* associated with this query. Sessions are how you mark a query as part of a
|
|
548
|
+
* [transaction](/docs/transactions.html).
|
|
549
|
+
*/
|
|
550
|
+
session(session: mongodb.ClientSession | null): this;
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Adds a `$set` to this query's update without changing the operation.
|
|
554
|
+
* This is useful for query middleware so you can add an update regardless
|
|
555
|
+
* of whether you use `updateOne()`, `updateMany()`, `findOneAndUpdate()`, etc.
|
|
556
|
+
*/
|
|
557
|
+
set(path: string | Record<string, unknown>, value?: any): this;
|
|
558
|
+
|
|
559
|
+
/** Sets query options. Some options only make sense for certain operations. */
|
|
560
|
+
setOptions(options: QueryOptions<DocType>, overwrite?: boolean): this;
|
|
561
|
+
|
|
562
|
+
/** Sets the query conditions to the provided JSON object. */
|
|
563
|
+
setQuery(val: FilterQuery<DocType> | null): void;
|
|
564
|
+
|
|
565
|
+
setUpdate(update: UpdateQuery<DocType> | UpdateWithAggregationPipeline): void;
|
|
566
|
+
|
|
567
|
+
/** Specifies an `$size` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
568
|
+
size<K extends keyof FilterQuery<DocType>>(path: K, val: FilterQuery<DocType>[K]['$size']): this;
|
|
569
|
+
size(val: number): this;
|
|
570
|
+
|
|
571
|
+
/** Specifies the number of documents to skip. */
|
|
572
|
+
skip(val: number): this;
|
|
573
|
+
|
|
574
|
+
/** Specifies a `$slice` projection for an array. */
|
|
575
|
+
slice(path: string, val: number | Array<number>): this;
|
|
576
|
+
slice(val: number | Array<number>): this;
|
|
577
|
+
|
|
578
|
+
/** Specifies this query as a `snapshot` query. */
|
|
579
|
+
snapshot(val?: boolean): this;
|
|
580
|
+
|
|
581
|
+
/** Sets the sort order. If an object is passed, values allowed are `asc`, `desc`, `ascending`, `descending`, `1`, and `-1`. */
|
|
582
|
+
sort(arg?: string | { [key: string]: SortOrder | { $meta: 'textScore' } } | undefined | null): this;
|
|
583
|
+
|
|
584
|
+
/** Sets the tailable option (for use with capped collections). */
|
|
585
|
+
tailable(bool?: boolean, opts?: {
|
|
586
|
+
numberOfRetries?: number;
|
|
587
|
+
tailableRetryInterval?: number;
|
|
588
|
+
}): this;
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Executes the query returning a `Promise` which will be
|
|
592
|
+
* resolved with either the doc(s) or rejected with the error.
|
|
593
|
+
*/
|
|
594
|
+
then: Promise<ResultType>['then'];
|
|
595
|
+
|
|
596
|
+
/** Converts this query to a customized, reusable query constructor with all arguments and options retained. */
|
|
597
|
+
toConstructor(): new (...args: any[]) => QueryWithHelpers<ResultType, DocType, THelpers, RawDocType>;
|
|
598
|
+
|
|
599
|
+
/** Declare and/or execute this query as an update() operation. */
|
|
600
|
+
update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Declare and/or execute this query as an updateMany() operation. Same as
|
|
604
|
+
* `update()`, except MongoDB will update _all_ documents that match
|
|
605
|
+
* `filter` (as opposed to just the first one) regardless of the value of
|
|
606
|
+
* the `multi` option.
|
|
607
|
+
*/
|
|
608
|
+
updateMany(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Declare and/or execute this query as an updateOne() operation. Same as
|
|
612
|
+
* `update()`, except it does not support the `multi` or `overwrite` options.
|
|
613
|
+
*/
|
|
614
|
+
updateOne(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Sets the specified number of `mongod` servers, or tag set of `mongod` servers,
|
|
618
|
+
* that must acknowledge this write before this write is considered successful.
|
|
619
|
+
*/
|
|
620
|
+
w(val: string | number | null): this;
|
|
621
|
+
|
|
622
|
+
/** Specifies a path for use with chaining. */
|
|
623
|
+
where(path: string, val?: any): this;
|
|
624
|
+
where(obj: object): this;
|
|
625
|
+
where(): this;
|
|
626
|
+
|
|
627
|
+
/** Defines a `$within` or `$geoWithin` argument for geo-spatial queries. */
|
|
628
|
+
within(val?: any): this;
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* If [`w > 1`](/docs/api.html#query_Query-w), the maximum amount of time to
|
|
632
|
+
* wait for this write to propagate through the replica set before this
|
|
633
|
+
* operation fails. The default is `0`, which means no timeout.
|
|
634
|
+
*/
|
|
635
|
+
wtimeout(ms: number): this;
|
|
636
|
+
}
|
|
637
|
+
}
|