UNPKG

27.5 kBTypeScriptView Raw
1declare module 'mongoose' {
2 import mongodb = require('mongodb');
3
4 export interface AcceptsDiscriminator {
5 /** Adds a discriminator type. */
6 discriminator<D>(name: string | number, schema: Schema, value?: string | number | ObjectId): Model<D>;
7 discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string | number | ObjectId): U;
8 }
9
10 interface MongooseBulkWriteOptions {
11 skipValidation?: boolean;
12 }
13
14 interface InsertManyOptions extends
15 PopulateOption,
16 SessionOption {
17 limit?: number;
18 rawResult?: boolean;
19 ordered?: boolean;
20 lean?: boolean;
21 }
22
23 type InsertManyResult<T> = mongodb.InsertManyResult<T> & {
24 insertedIds: {
25 [key: number]: InferId<T>;
26 };
27 mongoose?: { validationErrors?: Array<Error.CastError | Error.ValidatorError> };
28 };
29
30 type UpdateWriteOpResult = mongodb.UpdateResult;
31
32 interface MapReduceOptions<T, K, R> {
33 map: Function | string;
34 reduce: (key: K, vals: T[]) => R;
35 /** query filter object. */
36 query?: any;
37 /** sort input objects using this key */
38 sort?: any;
39 /** max number of documents */
40 limit?: number;
41 /** keep temporary data default: false */
42 keeptemp?: boolean;
43 /** finalize function */
44 finalize?: (key: K, val: R) => R;
45 /** scope variables exposed to map/reduce/finalize during execution */
46 scope?: any;
47 /** it is possible to make the execution stay in JS. Provided in MongoDB > 2.0.X default: false */
48 jsMode?: boolean;
49 /** provide statistics on job execution time. default: false */
50 verbose?: boolean;
51 readPreference?: string;
52 /** sets the output target for the map reduce job. default: {inline: 1} */
53 out?: {
54 /** the results are returned in an array */
55 inline?: number;
56 /**
57 * {replace: 'collectionName'} add the results to collectionName: the
58 * results replace the collection
59 */
60 replace?: string;
61 /**
62 * {reduce: 'collectionName'} add the results to collectionName: if
63 * dups are detected, uses the reducer / finalize functions
64 */
65 reduce?: string;
66 /**
67 * {merge: 'collectionName'} add the results to collectionName: if
68 * dups exist the new docs overwrite the old
69 */
70 merge?: string;
71 };
72 }
73
74 interface GeoSearchOptions {
75 /** x,y point to search for */
76 near: number[];
77 /** the maximum distance from the point near that a result can be */
78 maxDistance: number;
79 /** The maximum number of results to return */
80 limit?: number;
81 /** return the raw object instead of the Mongoose Model */
82 lean?: boolean;
83 }
84
85 interface ModifyResult<T> {
86 value: Require_id<T> | null;
87 /** see https://www.mongodb.com/docs/manual/reference/command/findAndModify/#lasterrorobject */
88 lastErrorObject?: {
89 updatedExisting?: boolean;
90 upserted?: mongodb.ObjectId;
91 };
92 ok: 0 | 1;
93 }
94
95 type WriteConcern = mongodb.WriteConcern;
96
97 /** A list of paths to validate. If set, Mongoose will validate only the modified paths that are in the given list. */
98 type PathsToValidate = string[] | string;
99 /**
100 * @deprecated
101 */
102 type pathsToValidate = PathsToValidate;
103
104 interface SaveOptions extends
105 SessionOption {
106 checkKeys?: boolean;
107 j?: boolean;
108 safe?: boolean | WriteConcern;
109 timestamps?: boolean | QueryTimestampsConfig;
110 validateBeforeSave?: boolean;
111 validateModifiedOnly?: boolean;
112 w?: number | string;
113 wtimeout?: number;
114 }
115
116 interface RemoveOptions extends SessionOption, Omit<mongodb.DeleteOptions, 'session'> {}
117
118 const Model: Model<any>;
119 interface Model<T, TQueryHelpers = {}, TMethodsAndOverrides = {}, TVirtuals = {}, TSchema = any> extends
120 NodeJS.EventEmitter,
121 AcceptsDiscriminator,
122 IndexManager,
123 SessionStarter {
124 new <DocType = T>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T, TMethodsAndOverrides,
125 IfEquals<TVirtuals, {}, ObtainSchemaGeneric<TSchema, 'TVirtuals'>, TVirtuals>> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
126
127 aggregate<R = any>(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
128 aggregate<R = any>(pipeline: PipelineStage[], callback?: Callback<R[]>): Aggregate<Array<R>>;
129
130 /** Base Mongoose instance the model uses. */
131 base: Mongoose;
132
133 /**
134 * If this is a discriminator model, `baseModelName` is the name of
135 * the base model.
136 */
137 baseModelName: string | undefined;
138
139 /* Cast the given POJO to the model's schema */
140 castObject(obj: AnyObject, options?: { ignoreCastErrors?: boolean }): T;
141
142 /**
143 * Sends multiple `insertOne`, `updateOne`, `updateMany`, `replaceOne`,
144 * `deleteOne`, and/or `deleteMany` operations to the MongoDB server in one
145 * command. This is faster than sending multiple independent operations (e.g.
146 * if you use `create()`) because with `bulkWrite()` there is only one network
147 * round trip to the MongoDB server.
148 */
149 bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T extends {} ? T : any>>, options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions, callback: Callback<mongodb.BulkWriteResult>): void;
150 bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T extends {} ? T : any>>, callback: Callback<mongodb.BulkWriteResult>): void;
151 bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T extends {} ? T : any>>, options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions): Promise<mongodb.BulkWriteResult>;
152
153 /**
154 * Sends multiple `save()` calls in a single `bulkWrite()`. This is faster than
155 * sending multiple `save()` calls because with `bulkSave()` there is only one
156 * network round trip to the MongoDB server.
157 */
158 bulkSave(documents: Array<Document>, options?: mongodb.BulkWriteOptions & { timestamps?: boolean }): Promise<mongodb.BulkWriteResult>;
159
160 /** Collection the model uses. */
161 collection: Collection;
162
163 /** Creates a `count` query: counts the number of documents that match `filter`. */
164 count(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
165 count(filter: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
166
167 /** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
168 countDocuments(filter: FilterQuery<T>, options?: QueryOptions<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
169 countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
170
171 /** Creates a new document or documents */
172 create<DocContents = AnyKeys<T>>(docs: Array<T | DocContents>, options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
173 create<DocContents = AnyKeys<T>>(docs: Array<T | DocContents>, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
174 create<DocContents = AnyKeys<T>>(doc: DocContents | T): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
175 create<DocContents = AnyKeys<T>>(...docs: Array<T | DocContents>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
176 create<DocContents = AnyKeys<T>>(doc: T | DocContents, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
177
178 /**
179 * Create the collection for this model. By default, if no indexes are specified,
180 * mongoose will not create the collection for the model until any documents are
181 * created. Use this method to create the collection explicitly.
182 */
183 createCollection<T extends mongodb.Document>(options: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'> | null, callback: Callback<mongodb.Collection<T>>): void;
184 createCollection<T extends mongodb.Document>(callback: Callback<mongodb.Collection<T>>): void;
185 createCollection<T extends mongodb.Document>(options?: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'>): Promise<mongodb.Collection<T>>;
186
187 /** Connection the model uses. */
188 db: Connection;
189
190 /**
191 * Deletes all of the documents that match `conditions` from the collection.
192 * Behaves like `remove()`, but deletes all documents that match `conditions`
193 * regardless of the `single` option.
194 */
195 deleteMany(filter?: FilterQuery<T>, options?: QueryOptions<T>, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
196 deleteMany(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
197 deleteMany(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
198
199 /**
200 * Deletes the first document that matches `conditions` from the collection.
201 * Behaves like `remove()`, but deletes at most one document regardless of the
202 * `single` option.
203 */
204 deleteOne(filter?: FilterQuery<T>, options?: QueryOptions<T>, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
205 deleteOne(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
206 deleteOne(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
207
208 /**
209 * Event emitter that reports any errors that occurred. Useful for global error
210 * handling.
211 */
212 events: NodeJS.EventEmitter;
213
214 /**
215 * Finds a single document by its _id field. `findById(id)` is almost*
216 * equivalent to `findOne({ _id: id })`. If you want to query by a document's
217 * `_id`, use `findById()` instead of `findOne()`.
218 */
219 findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
220 id: any,
221 projection?: ProjectionType<T> | null,
222 options?: QueryOptions<T> | null,
223 callback?: Callback<ResultDoc | null>
224 ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
225 findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
226 id: any,
227 projection?: ProjectionType<T> | null,
228 callback?: Callback<ResultDoc | null>
229 ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
230
231 /** Finds one document. */
232 findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
233 filter?: FilterQuery<T>,
234 projection?: ProjectionType<T> | null,
235 options?: QueryOptions<T> | null,
236 callback?: Callback<ResultDoc | null>
237 ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
238 findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
239 filter?: FilterQuery<T>,
240 projection?: ProjectionType<T> | null,
241 callback?: Callback<ResultDoc | null>
242 ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
243 findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
244 filter?: FilterQuery<T>,
245 callback?: Callback<ResultDoc | null>
246 ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
247
248 /**
249 * Shortcut for creating a new Document from existing raw data, pre-saved in the DB.
250 * The document returned has no paths marked as modified initially.
251 */
252 hydrate(obj: any, projection?: AnyObject, options?: { setters?: boolean }): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
253
254 /**
255 * This function is responsible for building [indexes](https://docs.mongodb.com/manual/indexes/),
256 * unless [`autoIndex`](http://mongoosejs.com/docs/guide.html#autoIndex) is turned off.
257 * Mongoose calls this function automatically when a model is created using
258 * [`mongoose.model()`](/docs/api.html#mongoose_Mongoose-model) or
259 * [`connection.model()`](/docs/api.html#connection_Connection-model), so you
260 * don't need to call it.
261 */
262 init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
263
264 /** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
265 insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { lean: true; }, callback: Callback<Array<MergeType<MergeType<T, DocContents>, Require_id<T>>>>): void;
266 insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { rawResult: true; }, callback: Callback<mongodb.InsertManyResult<T>>): void;
267 insertMany<DocContents = T>(docs: Array<DocContents | T>, callback: Callback<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>): void;
268 insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { lean: true; }, callback: Callback<Array<MergeType<MergeType<T, DocContents>, Require_id<T>>>>): void;
269 insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { rawResult: true; }, callback: Callback<mongodb.InsertManyResult<T>>): void;
270 insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { lean?: false | undefined }, callback: Callback<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>): void;
271 insertMany<DocContents = T>(doc: DocContents, callback: Callback<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>): void;
272
273 insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { lean: true; }): Promise<Array<MergeType<MergeType<T, DocContents>, Require_id<T>>>>;
274 insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { rawResult: true; }): Promise<mongodb.InsertManyResult<T>>;
275 insertMany<DocContents = T>(docs: Array<DocContents | T>): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>;
276 insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { lean: true; }): Promise<Array<MergeType<MergeType<T, DocContents>, Require_id<T>>>>;
277 insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { rawResult: true; }): Promise<mongodb.InsertManyResult<T>>;
278 insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>;
279 insertMany<DocContents = T>(doc: DocContents): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>;
280
281 /** The name of the model */
282 modelName: string;
283
284 /** Populates document references. */
285 populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
286 callback?: Callback<(HydratedDocument<T, TMethodsAndOverrides, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
287 populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string,
288 callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
289
290
291 /** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
292 validate(callback?: CallbackWithoutResult): Promise<void>;
293 validate(optional: any, callback?: CallbackWithoutResult): Promise<void>;
294 validate(optional: any, pathsToValidate: PathsToValidate, callback?: CallbackWithoutResult): Promise<void>;
295
296 /** Watches the underlying collection for changes using [MongoDB change streams](https://docs.mongodb.com/manual/changeStreams/). */
297 watch<ResultType extends mongodb.Document = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions & { hydrate?: boolean }): mongodb.ChangeStream<ResultType>;
298
299 /** Adds a `$where` clause to this query */
300 $where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
301
302 /** Registered discriminators for this model. */
303 discriminators: { [name: string]: Model<any> } | undefined;
304
305 /** Translate any aliases fields/conditions so the final query or document object is pure */
306 translateAliases(raw: any): any;
307
308 /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
309 distinct<ReturnType = any>(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
310
311 /** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
312 estimatedDocumentCount(options?: QueryOptions<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
313
314 /**
315 * Returns a document with its `_id` if at least one document exists in the database that matches
316 * the given `filter`, and `null` otherwise.
317 */
318 exists(filter: FilterQuery<T>, callback: Callback<{ _id: InferId<T> } | null>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
319 exists(filter: FilterQuery<T>): QueryWithHelpers<{ _id: InferId<T> } | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
320
321 /** Creates a `find` query: gets a list of documents that match `filter`. */
322 find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
323 filter: FilterQuery<T>,
324 projection?: ProjectionType<T> | null | undefined,
325 options?: QueryOptions<T> | null | undefined,
326 callback?: Callback<ResultDoc[]> | undefined
327 ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
328 find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
329 filter: FilterQuery<T>,
330 projection?: ProjectionType<T> | null | undefined,
331 callback?: Callback<ResultDoc[]> | undefined
332 ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
333 find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
334 filter: FilterQuery<T>,
335 callback?: Callback<ResultDoc[]> | undefined
336 ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
337 find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
338 callback?: Callback<ResultDoc[]> | undefined
339 ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
340
341 /** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
342 findByIdAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
343
344 /** Creates a `findByIdAndRemove` query, filtering by the given `_id`. */
345 findByIdAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
346
347 /** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
348 findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions<T> & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
349 findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions<T> & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
350 findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, update?: UpdateQuery<T>, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
351 findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, callback: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
352
353 /** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
354 findOneAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
355
356 /** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
357 findOneAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
358
359 /** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
360 findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions<T> & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
361 findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions<T> & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
362 findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
363
364 /** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
365 findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
366 filter: FilterQuery<T>,
367 update: UpdateQuery<T>,
368 options: QueryOptions<T> & { rawResult: true },
369 callback?: (err: CallbackError, doc: any, res: any) => void
370 ): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
371 findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
372 filter: FilterQuery<T>,
373 update: UpdateQuery<T>,
374 options: QueryOptions<T> & { upsert: true } & ReturnsNewDoc,
375 callback?: (err: CallbackError, doc: ResultDoc, res: any) => void
376 ): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
377 findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
378 filter?: FilterQuery<T>,
379 update?: UpdateQuery<T>,
380 options?: QueryOptions<T> | null,
381 callback?: (err: CallbackError, doc: T | null, res: any) => void
382 ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
383
384 geoSearch<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
385 filter?: FilterQuery<T>,
386 options?: GeoSearchOptions,
387 callback?: Callback<Array<ResultDoc>>
388 ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
389
390 /** Executes a mapReduce command. */
391 mapReduce<Key, Value>(
392 o: MapReduceOptions<T, Key, Value>,
393 callback?: Callback
394 ): Promise<any>;
395
396 remove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: any, callback?: CallbackWithoutResult): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
397 remove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: any, options?: RemoveOptions, callback?: CallbackWithoutResult): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
398
399 /** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
400 replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
401 filter?: FilterQuery<T>,
402 replacement?: T | AnyObject,
403 options?: QueryOptions<T> | null,
404 callback?: Callback
405 ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
406
407 /** Schema the model uses. */
408 schema: Schema<T>;
409
410 /**
411 * @deprecated use `updateOne` or `updateMany` instead.
412 * Creates a `update` query: updates one or many documents that match `filter` with `update`, based on the `multi` option.
413 */
414 update<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
415 filter?: FilterQuery<T>,
416 update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
417 options?: QueryOptions<T> | null,
418 callback?: Callback
419 ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
420
421 /** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
422 updateMany<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
423 filter?: FilterQuery<T>,
424 update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
425 options?: QueryOptions<T> | null,
426 callback?: Callback
427 ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
428
429 /** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
430 updateOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
431 filter?: FilterQuery<T>,
432 update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
433 options?: QueryOptions<T> | null,
434 callback?: Callback
435 ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
436
437 /** Creates a Query, applies the passed conditions, and returns the Query. */
438 where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(path: string, val?: any): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
439 where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(obj: object): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
440 where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
441 }
442}
443
\No newline at end of file