UNPKG

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