-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathindex.d.ts
2382 lines (1940 loc) · 111 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// <reference path="./aggregate.d.ts" />
/// <reference path="./connection.d.ts" />
/// <reference path="./cursor.d.ts" />
/// <reference path="./document.d.ts" />
/// <reference path="./error.d.ts" />
/// <reference path="./mongooseoptions.d.ts" />
/// <reference path="./pipelinestage.d.ts" />
/// <reference path="./schemaoptions.d.ts" />
declare class NativeDate extends global.Date { }
declare module 'mongoose' {
import events = require('events');
import mongodb = require('mongodb');
import mongoose = require('mongoose');
/** The Mongoose Date [SchemaType](/docs/schematypes.html). */
export type Date = Schema.Types.Date;
/**
* The Mongoose Decimal128 [SchemaType](/docs/schematypes.html). Used for
* declaring paths in your schema that should be
* [128-bit decimal floating points](http://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-34-decimal.html).
* Do not use this to create a new Decimal128 instance, use `mongoose.Types.Decimal128`
* instead.
*/
export type Decimal128 = Schema.Types.Decimal128;
/**
* The Mongoose Mixed [SchemaType](/docs/schematypes.html). Used for
* declaring paths in your schema that Mongoose's change tracking, casting,
* and validation should ignore.
*/
export type Mixed = Schema.Types.Mixed;
export type Mongoose = typeof mongoose;
/**
* Mongoose constructor. The exports object of the `mongoose` module is an instance of this
* class. Most apps will only use this one instance.
*/
export const Mongoose: new (options?: MongooseOptions | null) => Mongoose;
/**
* The Mongoose Number [SchemaType](/docs/schematypes.html). Used for
* declaring paths in your schema that Mongoose should cast to numbers.
*/
export type Number = Schema.Types.Number;
/**
* The Mongoose ObjectId [SchemaType](/docs/schematypes.html). Used for
* declaring paths in your schema that should be
* [MongoDB ObjectIds](https://docs.mongodb.com/manual/reference/method/ObjectId/).
* Do not use this to create a new ObjectId instance, use `mongoose.Types.ObjectId`
* instead.
*/
export type ObjectId = Schema.Types.ObjectId;
export let Promise: any;
export const PromiseProvider: any;
/** The various Mongoose SchemaTypes. */
export const SchemaTypes: typeof Schema.Types;
/** Opens Mongoose's default connection to MongoDB, see [connections docs](https://mongoosejs.com/docs/connections.html) */
export function connect(uri: string, options: ConnectOptions, callback: CallbackWithoutResult): void;
export function connect(uri: string, callback: CallbackWithoutResult): void;
export function connect(uri: string, options?: ConnectOptions): Promise<Mongoose>;
/**
* Makes the indexes in MongoDB match the indexes defined in every model's
* schema. This function will drop any indexes that are not defined in
* the model's schema except the `_id` index, and build any indexes that
* are in your schema but not in MongoDB.
*/
export function syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
export function syncIndexes(options: SyncIndexesOptions | null, callback: Callback<ConnectionSyncIndexesResult>): void;
/* Tells `sanitizeFilter()` to skip the given object when filtering out potential query selector injection attacks.
* Use this method when you have a known query selector that you want to use. */
export function trusted<T>(obj: T): T;
/** The Mongoose module's default connection. Equivalent to `mongoose.connections[0]`, see [`connections`](#mongoose_Mongoose-connections). */
export const connection: Connection;
/** An array containing all connections associated with this Mongoose instance. */
export const connections: Connection[];
/**
* Can be extended to explicitly type specific models.
*/
export interface Models {
[modelName: string]: Model<any>
}
/** An array containing all models associated with this Mongoose instance. */
export const models: Models;
/** Creates a Connection instance. */
export function createConnection(uri: string, options: ConnectOptions, callback: Callback<Connection>): void;
export function createConnection(uri: string, options?: ConnectOptions): Connection;
export function createConnection(): Connection;
/**
* Removes the model named `name` from the default connection, if it exists.
* You can use this function to clean up any models you created in your tests to
* prevent OverwriteModelErrors.
*/
export function deleteModel(name: string | RegExp): Mongoose;
export function disconnect(): Promise<void>;
export function disconnect(cb: CallbackWithoutResult): void;
/** Gets mongoose options */
export function get<K extends keyof MongooseOptions>(key: K): MongooseOptions[K];
/* ! ignore */
export type CompileModelOptions = { overwriteModels?: boolean, connection?: Connection };
/**
* Returns true if Mongoose can cast the given value to an ObjectId, or
* false otherwise.
*/
export function isValidObjectId(v: Types.ObjectId): true;
export function isValidObjectId(v: any): boolean;
/**
* Returns true if the given value is a Mongoose ObjectId (using `instanceof`) or if the
* given value is a 24 character hex string, which is the most commonly used string representation
* of an ObjectId.
*/
export function isObjectIdOrHexString(v: any): boolean;
export function model<T>(name: string, schema?: Schema<T, any, any> | Schema<T & Document, any, any>, collection?: string, options?: CompileModelOptions): Model<T>;
export function model<T, U, TQueryHelpers = {}>(
name: string,
schema?: Schema<T, U, TQueryHelpers>,
collection?: string,
options?: CompileModelOptions
): U;
/** Returns an array of model names created on this instance of Mongoose. */
export function modelNames(): Array<string>;
/** The node-mongodb-native driver Mongoose uses. */
export const mongo: typeof mongodb;
/**
* Mongoose uses this function to get the current time when setting
* [timestamps](/docs/guide.html#timestamps). You may stub out this function
* using a tool like [Sinon](https://www.npmjs.com/package/sinon) for testing.
*/
export function now(): NativeDate;
/** Declares a global plugin executed on all Schemas. */
export function plugin(fn: (schema: Schema, opts?: any) => void, opts?: any): Mongoose;
/** Getter/setter around function for pluralizing collection names. */
export function pluralize(fn?: ((str: string) => string) | null): ((str: string) => string) | null;
/** Sets mongoose options */
export function set<K extends keyof MongooseOptions>(key: K, value: MongooseOptions[K]): Mongoose;
/**
* _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
* for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
* and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
*/
export function startSession(options?: mongodb.ClientSessionOptions): Promise<mongodb.ClientSession>;
export function startSession(options: mongodb.ClientSessionOptions, cb: Callback<mongodb.ClientSession>): void;
/** The Mongoose version */
export const version: string;
export type CastError = Error.CastError;
export type SyncIndexesError = Error.SyncIndexesError;
export type ClientSession = mongodb.ClientSession;
/*
* section collection.js
* http://mongoosejs.com/docs/api.html#collection-js
*/
export interface CollectionBase<T extends mongodb.Document> extends mongodb.Collection<T> {
/*
* Abstract methods. Some of these are already defined on the
* mongodb.Collection interface so they've been commented out.
*/
ensureIndex(...args: any[]): any;
findAndModify(...args: any[]): any;
getIndexes(...args: any[]): any;
/** The collection name */
collectionName: string;
/** The Connection instance */
conn: Connection;
/** The collection name */
name: string;
}
/*
* section drivers/node-mongodb-native/collection.js
* http://mongoosejs.com/docs/api.html#drivers-node-mongodb-native-collection-js
*/
export let Collection: Collection;
export interface Collection<T extends mongodb.Document = mongodb.Document> extends CollectionBase<T> {
/**
* Collection constructor
* @param name name of the collection
* @param conn A MongooseConnection instance
* @param opts optional collection options
*/
// eslint-disable-next-line @typescript-eslint/no-misused-new
new(name: string, conn: Connection, opts?: any): Collection<T>;
/** Formatter for debug print args */
$format(arg: any): string;
/** Debug print helper */
$print(name: any, i: any, args: any[]): void;
/** Retrieves information about this collections indexes. */
getIndexes(): any;
}
/** A list of paths to validate. If set, Mongoose will validate only the modified paths that are in the given list. */
export type pathsToValidate = string[] | string;
export interface AcceptsDiscriminator {
/** Adds a discriminator type. */
discriminator<D>(name: string | number, schema: Schema, value?: string | number | ObjectId): Model<D>;
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string | number | ObjectId): U;
}
export type AnyKeys<T> = { [P in keyof T]?: T[P] | any };
export interface AnyObject {
[k: string]: any
}
export type Require_id<T> = T extends { _id?: any } ? (T & { _id: T['_id'] }) : (T & { _id: Types.ObjectId });
export type HydratedDocument<DocType, TMethodsAndOverrides = {}, TVirtuals = {}> = DocType extends Document ? Require_id<DocType> : (Document<unknown, any, DocType> & Require_id<DocType> & TVirtuals & TMethodsAndOverrides);
interface IndexesDiff {
/** Indexes that would be created in mongodb. */
toCreate: Array<any>
/** Indexes that would be dropped in mongodb. */
toDrop: Array<any>
}
export interface ModifyResult<T> {
value: Require_id<T> | null;
/** see https://www.mongodb.com/docs/manual/reference/command/findAndModify/#lasterrorobject */
lastErrorObject?: {
updatedExisting?: boolean;
upserted?: mongodb.ObjectId;
};
ok: 0 | 1;
}
export const Model: Model<any>;
export interface Model<T, TQueryHelpers = {}, TMethodsAndOverrides = {}, TVirtuals = {}> extends NodeJS.EventEmitter, AcceptsDiscriminator {
new <DocType = AnyKeys<T> & AnyObject>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
aggregate<R = any>(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
aggregate<R = any>(pipeline: PipelineStage[], cb: Function): Aggregate<Array<R>>;
/** Base Mongoose instance the model uses. */
base: Mongoose;
/**
* If this is a discriminator model, `baseModelName` is the name of
* the base model.
*/
baseModelName: string | undefined;
/**
* Sends multiple `insertOne`, `updateOne`, `updateMany`, `replaceOne`,
* `deleteOne`, and/or `deleteMany` operations to the MongoDB server in one
* command. This is faster than sending multiple independent operations (e.g.
* if you use `create()`) because with `bulkWrite()` there is only one network
* round trip to the MongoDB server.
*/
bulkWrite(writes: Array<any>, options?: mongodb.BulkWriteOptions): Promise<mongodb.BulkWriteResult>;
bulkWrite(writes: Array<any>, options?: mongodb.BulkWriteOptions, cb?: Callback<mongodb.BulkWriteResult>): void;
/**
* Sends multiple `save()` calls in a single `bulkWrite()`. This is faster than
* sending multiple `save()` calls because with `bulkSave()` there is only one
* network round trip to the MongoDB server.
*/
bulkSave(documents: Array<Document>, options?: mongodb.BulkWriteOptions): Promise<mongodb.BulkWriteResult>;
/** Collection the model uses. */
collection: Collection;
/** Creates a `count` query: counts the number of documents that match `filter`. */
count(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
count(filter: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
countDocuments(filter: FilterQuery<T>, options?: QueryOptions<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/** Creates a new document or documents */
create(docs: (AnyKeys<T> | AnyObject)[], options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
create(docs: (AnyKeys<T> | AnyObject)[], callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
create(doc: AnyKeys<T> | AnyObject): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
create(doc: AnyKeys<T> | AnyObject, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
create<DocContents = AnyKeys<T>>(docs: DocContents[], options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
create<DocContents = AnyKeys<T>>(docs: DocContents[], callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
create<DocContents = AnyKeys<T>>(doc: DocContents): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
create<DocContents = AnyKeys<T>>(...docs: DocContents[]): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
create<DocContents = AnyKeys<T>>(doc: DocContents, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
/**
* Create the collection for this model. By default, if no indexes are specified,
* mongoose will not create the collection for the model until any documents are
* created. Use this method to create the collection explicitly.
*/
createCollection<T extends mongodb.Document>(options?: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'>): Promise<mongodb.Collection<T>>;
createCollection<T extends mongodb.Document>(options: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'> | null, callback: Callback<mongodb.Collection<T>>): void;
/**
* Similar to `ensureIndexes()`, except for it uses the [`createIndex`](http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#createIndex)
* function.
*/
createIndexes(callback?: CallbackWithoutResult): Promise<void>;
createIndexes(options?: any, callback?: CallbackWithoutResult): Promise<void>;
/** Connection the model uses. */
db: Connection;
/**
* Deletes all of the documents that match `conditions` from the collection.
* Behaves like `remove()`, but deletes all documents that match `conditions`
* regardless of the `single` option.
*/
deleteMany(filter?: FilterQuery<T>, options?: QueryOptions<T>, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
deleteMany(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
deleteMany(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/**
* Deletes the first document that matches `conditions` from the collection.
* Behaves like `remove()`, but deletes at most one document regardless of the
* `single` option.
*/
deleteOne(filter?: FilterQuery<T>, options?: QueryOptions<T>, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
deleteOne(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
deleteOne(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/**
* Sends `createIndex` commands to mongo for each index declared in the schema.
* The `createIndex` commands are sent in series.
*/
ensureIndexes(callback?: CallbackWithoutResult): Promise<void>;
ensureIndexes(options?: any, callback?: CallbackWithoutResult): Promise<void>;
/**
* Event emitter that reports any errors that occurred. Useful for global error
* handling.
*/
events: NodeJS.EventEmitter;
/**
* Finds a single document by its _id field. `findById(id)` is almost*
* equivalent to `findOne({ _id: id })`. If you want to query by a document's
* `_id`, use `findById()` instead of `findOne()`.
*/
findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
id: any,
projection?: ProjectionType<T> | null,
options?: QueryOptions<T> | null,
callback?: Callback<ResultDoc | null>
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
id: any,
projection?: ProjectionType<T> | null,
callback?: Callback<ResultDoc | null>
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
/** Finds one document. */
findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
projection?: ProjectionType<T> | null,
options?: QueryOptions<T> | null,
callback?: Callback<ResultDoc | null>
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
projection?: ProjectionType<T> | null,
callback?: Callback<ResultDoc | null>
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
callback?: Callback<ResultDoc | null>
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
/**
* Shortcut for creating a new Document from existing raw data, pre-saved in the DB.
* The document returned has no paths marked as modified initially.
*/
hydrate(obj: any): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
/**
* This function is responsible for building [indexes](https://docs.mongodb.com/manual/indexes/),
* unless [`autoIndex`](http://mongoosejs.com/docs/guide.html#autoIndex) is turned off.
* Mongoose calls this function automatically when a model is created using
* [`mongoose.model()`](/docs/api.html#mongoose_Mongoose-model) or
* [`connection.model()`](/docs/api.html#connection_Connection-model), so you
* don't need to call it.
*/
init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
/** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult<T>>;
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
insertMany(doc: AnyKeys<T> | AnyObject, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult<T>>;
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[] | InsertManyResult<T>>): void;
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>> | InsertManyResult<T>>): void;
/**
* Lists the indexes currently defined in MongoDB. This may or may not be
* the same as the indexes defined in your schema depending on whether you
* use the [`autoIndex` option](/docs/guide.html#autoIndex) and if you
* build indexes manually.
*/
listIndexes(callback: Callback<Array<any>>): void;
listIndexes(): Promise<Array<any>>;
/** The name of the model */
modelName: string;
/** Populates document references. */
populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
callback?: Callback<(HydratedDocument<T, TMethodsAndOverrides, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string,
callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
/**
* Makes the indexes in MongoDB match the indexes defined in this model's
* schema. This function will drop any indexes that are not defined in
* the model's schema except the `_id` index, and build any indexes that
* are in your schema but not in MongoDB.
*/
syncIndexes(options?: Record<string, unknown>): Promise<Array<string>>;
syncIndexes(options: Record<string, unknown> | null, callback: Callback<Array<string>>): void;
/**
* Does a dry-run of Model.syncIndexes(), meaning that
* the result of this function would be the result of
* Model.syncIndexes().
*/
diffIndexes(options?: Record<string, unknown>): Promise<IndexesDiff>
diffIndexes(options: Record<string, unknown> | null, callback: (err: CallbackError, diff: IndexesDiff) => void): void
/**
* Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
* for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
* and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
* */
startSession(options?: mongodb.ClientSessionOptions, cb?: Callback<mongodb.ClientSession>): Promise<mongodb.ClientSession>;
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
validate(callback?: CallbackWithoutResult): Promise<void>;
validate(optional: any, callback?: CallbackWithoutResult): Promise<void>;
validate(optional: any, pathsToValidate: pathsToValidate, callback?: CallbackWithoutResult): Promise<void>;
/** Watches the underlying collection for changes using [MongoDB change streams](https://docs.mongodb.com/manual/changeStreams/). */
watch<ResultType extends mongodb.Document = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
/** Adds a `$where` clause to this query */
$where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/** Registered discriminators for this model. */
discriminators: { [name: string]: Model<any> } | undefined;
/** Translate any aliases fields/conditions so the final query or document object is pure */
translateAliases(raw: any): any;
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
distinct<ReturnType = any>(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
estimatedDocumentCount(options?: QueryOptions<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/**
* Returns a document with its `_id` if at least one document exists in the database that matches
* the given `filter`, and `null` otherwise.
*/
exists(filter: FilterQuery<T>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
exists(filter: FilterQuery<T>, callback: Callback<Pick<Document<T>, '_id'> | null>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/** Creates a `find` query: gets a list of documents that match `filter`. */
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter: FilterQuery<T>,
projection?: ProjectionType<T> | null,
callback?: Callback<ResultDoc[]>
): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, projection?: ProjectionType<T> | null, options?: QueryOptions<T> | null, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
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>;
/** Creates a `findByIdAndRemove` query, filtering by the given `_id`. */
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>;
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
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>;
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>;
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>;
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>;
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
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>;
/** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
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>;
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
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>;
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>;
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter: FilterQuery<T>,
update: UpdateQuery<T>,
options: QueryOptions<T> & { rawResult: true },
callback?: (err: CallbackError, doc: any, res: any) => void
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter: FilterQuery<T>,
update: UpdateQuery<T>,
options: QueryOptions<T> & { upsert: true } & ReturnsNewDoc,
callback?: (err: CallbackError, doc: ResultDoc, res: any) => void
): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
update?: UpdateQuery<T>,
options?: QueryOptions<T> | null,
callback?: (err: CallbackError, doc: T | null, res: any) => void
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
geoSearch<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
options?: GeoSearchOptions,
callback?: Callback<Array<ResultDoc>>
): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
/** Executes a mapReduce command. */
mapReduce<Key, Value>(
o: MapReduceOptions<T, Key, Value>,
callback?: Callback
): Promise<any>;
remove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: any, callback?: CallbackWithoutResult): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
/** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
replacement?: T | AnyObject,
options?: QueryOptions<T> | null,
callback?: Callback
): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
replacement?: T | AnyObject,
options?: QueryOptions<T> | null,
callback?: Callback
): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
/** Schema the model uses. */
schema: Schema<T>;
/**
* @deprecated use `updateOne` or `updateMany` instead.
* Creates a `update` query: updates one or many documents that match `filter` with `update`, based on the `multi` option.
*/
update<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
options?: QueryOptions<T> | null,
callback?: Callback
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
/** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
updateMany<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
options?: QueryOptions<T> | null,
callback?: Callback
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
/** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
updateOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
filter?: FilterQuery<T>,
update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
options?: QueryOptions<T> | null,
callback?: Callback
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
/** Creates a Query, applies the passed conditions, and returns the Query. */
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(path: string, val?: any): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(obj: object): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
}
export type UpdateWriteOpResult = mongodb.UpdateResult;
export interface QueryOptions<DocType = unknown> {
arrayFilters?: { [key: string]: any }[];
batchSize?: number;
collation?: mongodb.CollationOptions;
comment?: any;
context?: string;
explain?: any;
fields?: any | string;
hint?: any;
/**
* If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.
*/
lean?: boolean | any;
limit?: number;
maxTimeMS?: number;
maxscan?: number;
multi?: boolean;
multipleCastError?: boolean;
/**
* By default, `findOneAndUpdate()` returns the document as it was **before**
* `update` was applied. If you set `new: true`, `findOneAndUpdate()` will
* instead give you the object after `update` was applied.
*/
new?: boolean;
overwrite?: boolean;
overwriteDiscriminatorKey?: boolean;
populate?: string | string[] | PopulateOptions | PopulateOptions[];
projection?: ProjectionType<DocType>;
/**
* if true, returns the raw result from the MongoDB driver
*/
rawResult?: boolean;
readPreference?: string | mongodb.ReadPreferenceMode;
/**
* An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`.
*/
returnOriginal?: boolean;
/**
* Another alias for the `new` option. `returnOriginal` is deprecated so this should be used.
*/
returnDocument?: string;
runValidators?: boolean;
/* Set to `true` to automatically sanitize potentially unsafe user-generated query projections */
sanitizeProjection?: boolean;
/**
* Set to `true` to automatically sanitize potentially unsafe query filters by stripping out query selectors that
* aren't explicitly allowed using `mongoose.trusted()`.
*/
sanitizeFilter?: boolean;
/** The session associated with this query. */
session?: mongodb.ClientSession;
setDefaultsOnInsert?: boolean;
skip?: number;
snapshot?: any;
sort?: any;
/** overwrites the schema's strict mode option */
strict?: boolean | string;
/**
* equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default
* [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
*/
strictQuery?: boolean | 'throw';
tailable?: number;
/**
* If set to `false` and schema-level timestamps are enabled,
* skip timestamps for this update. Note that this allows you to overwrite
* timestamps. Does nothing if schema-level timestamps are not set.
*/
timestamps?: boolean;
upsert?: boolean;
writeConcern?: any;
[other: string]: any;
}
export type MongooseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, 'populate' | 'lean' | 'strict' | 'sanitizeProjection' | 'sanitizeFilter'>;
export interface SaveOptions {
checkKeys?: boolean;
j?: boolean;
safe?: boolean | WriteConcern;
session?: ClientSession | null;
timestamps?: boolean;
validateBeforeSave?: boolean;
validateModifiedOnly?: boolean;
w?: number | string;
wtimeout?: number;
}
export interface WriteConcern {
j?: boolean;
w?: number | 'majority' | TagSet;
wtimeout?: number;
}
export interface TagSet {
[k: string]: string;
}
export interface InsertManyOptions {
limit?: number;
rawResult?: boolean;
ordered?: boolean;
lean?: boolean;
session?: mongodb.ClientSession;
populate?: string | string[] | PopulateOptions | PopulateOptions[];
}
export type InferIdType<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
export type InsertManyResult<T> = mongodb.InsertManyResult<T> & {
insertedIds: {
[key: number]: InferIdType<T>;
};
mongoose?: { validationErrors?: Array<Error.CastError | Error.ValidatorError> };
};
export interface MapReduceOptions<T, Key, Val> {
map: Function | string;
reduce: (key: Key, vals: T[]) => Val;
/** query filter object. */
query?: any;
/** sort input objects using this key */
sort?: any;
/** max number of documents */
limit?: number;
/** keep temporary data default: false */
keeptemp?: boolean;
/** finalize function */
finalize?: (key: Key, val: Val) => Val;
/** scope variables exposed to map/reduce/finalize during execution */
scope?: any;
/** it is possible to make the execution stay in JS. Provided in MongoDB > 2.0.X default: false */
jsMode?: boolean;
/** provide statistics on job execution time. default: false */
verbose?: boolean;
readPreference?: string;
/** sets the output target for the map reduce job. default: {inline: 1} */
out?: {
/** the results are returned in an array */
inline?: number;
/**
* {replace: 'collectionName'} add the results to collectionName: the
* results replace the collection
*/
replace?: string;
/**
* {reduce: 'collectionName'} add the results to collectionName: if
* dups are detected, uses the reducer / finalize functions
*/
reduce?: string;
/**
* {merge: 'collectionName'} add the results to collectionName: if
* dups exist the new docs overwrite the old
*/
merge?: string;
};
}
export interface GeoSearchOptions {
/** x,y point to search for */
near: number[];
/** the maximum distance from the point near that a result can be */
maxDistance: number;
/** The maximum number of results to return */
limit?: number;
/** return the raw object instead of the Mongoose Model */
lean?: boolean;
}
export interface PopulateOptions {
/** space delimited path(s) to populate */
path: string;
/** fields to select */
select?: any;
/** query conditions to match */
match?: any;
/** optional model to use for population */
model?: string | Model<any>;
/** optional query options like sort, limit, etc */
options?: any;
/** correct limit on populated array */
perDocumentLimit?: number;
/** optional boolean, set to `false` to allow populating paths that aren't in the schema */
strictPopulate?: boolean;
/** deep populate */
populate?: string | PopulateOptions | (string | PopulateOptions)[];
/**
* If true Mongoose will always set `path` to an array, if false Mongoose will
* always set `path` to a document. Inferred from schema by default.
*/
justOne?: boolean;
/** transform function to call on every populated doc */
transform?: (doc: any, id: any) => any;
}
export interface ToObjectOptions {
/** apply all getters (path and virtual getters) */
getters?: boolean;
/** apply virtual getters (can override getters option) */
virtuals?: boolean | string[];
/** if `options.virtuals = true`, you can set `options.aliases = false` to skip applying aliases. This option is a no-op if `options.virtuals = false`. */
aliases?: boolean;
/** remove empty objects (defaults to true) */
minimize?: boolean;
/** if set, mongoose will call this function to allow you to transform the returned object */
transform?: boolean | ((doc: any, ret: any, options: any) => any);
/** if true, replace any conventionally populated paths with the original id in the output. Has no affect on virtual populated paths. */
depopulate?: boolean;
/** if false, exclude the version key (`__v` by default) from the output */
versionKey?: boolean;
/** if true, convert Maps to POJOs. Useful if you want to `JSON.stringify()` the result of `toObject()`. */
flattenMaps?: boolean;
/** If true, omits fields that are excluded in this document's projection. Unless you specified a projection, this will omit any field that has `select: false` in the schema. */
useProjection?: boolean;
}
export type MongooseDocumentMiddleware = 'validate' | 'save' | 'remove' | 'updateOne' | 'deleteOne' | 'init';
export type MongooseQueryMiddleware = 'count' | 'deleteMany' | 'deleteOne' | 'distinct' | 'find' | 'findOne' | 'findOneAndDelete' | 'findOneAndRemove' | 'findOneAndUpdate' | 'remove' | 'update' | 'updateOne' | 'updateMany';
export type SchemaPreOptions = { document?: boolean, query?: boolean };
export type SchemaPostOptions = { document?: boolean, query?: boolean };
export type IndexDirection = 1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text';
export type IndexDefinition = Record<string, IndexDirection>;
export type PreMiddlewareFunction<ThisType = any> = (this: ThisType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>;
export type PreSaveMiddlewareFunction<ThisType = any> = (this: ThisType, next: CallbackWithoutResultAndOptionalError, opts: SaveOptions) => void | Promise<void>;
export type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>;
export type ErrorHandlingMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: CallbackWithoutResultAndOptionalError) => void;
export class Schema<DocType = any, M = Model<DocType, any, any, any>, TInstanceMethods = {}, TQueryHelpers = {}> extends events.EventEmitter {
/**
* Create a new schema
*/
constructor(definition?: SchemaDefinition<SchemaDefinitionType<DocType>>, options?: SchemaOptions);
/** Adds key path / schema type pairs to this schema. */
add(obj: SchemaDefinition<SchemaDefinitionType<DocType>> | Schema, prefix?: string): this;
/**
* Array of child schemas (from document arrays and single nested subdocs)
* and their corresponding compiled models. Each element of the array is
* an object with 2 properties: `schema` and `model`.
*/
childSchemas: { schema: Schema, model: any }[];
/** Removes all indexes on this schema */
clearIndexes(): this;
/** Returns a copy of this schema */
clone<T = this>(): T;
/** Returns a new schema that has the picked `paths` from this schema. */
pick<T = this>(paths: string[], options?: SchemaOptions): T;
/** Object containing discriminators defined on this schema */
discriminators?: { [name: string]: Schema };
/** Iterates the schemas paths similar to Array#forEach. */
eachPath(fn: (path: string, type: SchemaType) => void): this;
/** Defines an index (most likely compound) for this schema. */
index(fields: IndexDefinition, options?: IndexOptions): this;
/**
* Returns a list of indexes that this schema declares, via `schema.index()`
* or by `index: true` in a path's options.
*/
indexes(): Array<IndexDefinition>;
/** Gets a schema option. */
get<K extends keyof SchemaOptions>(key: K): SchemaOptions[K];
/**
* Loads an ES6 class into a schema. Maps [setters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set) + [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get), [static methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static),
* and [instance methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Class_body_and_method_definitions)
* to schema [virtuals](http://mongoosejs.com/docs/guide.html#virtuals),
* [statics](http://mongoosejs.com/docs/guide.html#statics), and
* [methods](http://mongoosejs.com/docs/guide.html#methods).
*/
loadClass(model: Function, onlyVirtuals?: boolean): this;
/** Adds an instance method to documents constructed from Models compiled from this schema. */
method<Context = any>(name: string, fn: (this: Context, ...args: any[]) => any, opts?: any): this;
method(obj: Partial<TInstanceMethods>): this;
/** Object of currently defined methods on this schema. */
methods: { [F in keyof TInstanceMethods]: TInstanceMethods[F] } & AnyObject;
/** The original object passed to the schema constructor */
obj: SchemaDefinition<SchemaDefinitionType<DocType>>;
/** Gets/sets schema paths. */
path<ResultType extends SchemaType = SchemaType>(path: string): ResultType;
path(path: string, constructor: any): this;
/** Lists all paths and their type in the schema. */
paths: {
[key: string]: SchemaType;
};
/** Returns the pathType of `path` for this schema. */
pathType(path: string): string;
/** Registers a plugin for this schema. */
plugin(fn: (schema: Schema<DocType>, opts?: any) => void, opts?: any): this;
/** Defines a post hook for the model. */
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T>): this;
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T>): this;
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PostMiddlewareFunction<T>): this;
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T>): this;
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PostMiddlewareFunction<T, Array<any>>): this;
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, Array<any>>): this;
post<T = M>(method: 'insertMany' | RegExp, fn: PostMiddlewareFunction<T>): this;
post<T = M>(method: 'insertMany' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T>): this;
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: ErrorHandlingMiddlewareFunction<T, Array<any>>): this;
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T, Array<any>>): this;
post<T = M>(method: 'insertMany' | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T = M>(method: 'insertMany' | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
/** Defines a pre hook for the model. */
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', fn: PreSaveMiddlewareFunction<T>): this;
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', options: SchemaPreOptions, fn: PreSaveMiddlewareFunction<T>): this;
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
pre<T extends Query<any, any>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PreMiddlewareFunction<T>): this;
pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
pre<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PreMiddlewareFunction<T>): this;
pre<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
pre<T = M>(method: 'insertMany' | RegExp, fn: (this: T, next: (err?: CallbackError) => void, docs: any | Array<any>) => void | Promise<void>): this;
pre<T = M>(method: 'insertMany' | RegExp, options: SchemaPreOptions, fn: (this: T, next: (err?: CallbackError) => void, docs: any | Array<any>) => void | Promise<void>): this;
/** Object of currently defined query helpers on this schema. */
query: TQueryHelpers;
/** Adds a method call to the queue. */
queue(name: string, args: any[]): this;
/** Removes the given `path` (or [`paths`]). */
remove(paths: string | Array<string>): this;
/** Removes index by name or index spec */
remove(index: string | AnyObject): this;
/** Returns an Array of path strings that are required by this schema. */
requiredPaths(invalidate?: boolean): string[];
/** Sets a schema option. */
set<K extends keyof SchemaOptions>(key: K, value: SchemaOptions[K], _tags?: any): this;
/** Adds static "class" methods to Models compiled from this schema. */
static(name: string, fn: (this: M, ...args: any[]) => any): this;
static(obj: { [name: string]: (this: M, ...args: any[]) => any }): this;
/** Object of currently defined statics on this schema. */
statics: { [name: string]: (this: M, ...args: any[]) => any };
/** Creates a virtual type with the given name. */
virtual<T = HydratedDocument<DocType, TInstanceMethods>>(
name: string,
options?: VirtualTypeOptions<T, DocType>
): VirtualType<T>;
/** Object of currently defined virtuals on this schema */
virtuals: any;
/** Returns the virtual type with the given `name`. */
virtualpath<T = HydratedDocument<DocType, TInstanceMethods>>(name: string): VirtualType<T> | null;
}
export type NumberSchemaDefinition = typeof Number | 'number' | 'Number' | typeof Schema.Types.Number;
export type StringSchemaDefinition = typeof String | 'string' | 'String' | typeof Schema.Types.String;
export type BooleanSchemaDefinition = typeof Boolean | 'boolean' | 'Boolean' | typeof Schema.Types.Boolean;
export type DateSchemaDefinition = typeof NativeDate | 'date' | 'Date' | typeof Schema.Types.Date;
export type ObjectIdSchemaDefinition = 'ObjectId' | 'ObjectID' | typeof Schema.Types.ObjectId;
export type SchemaDefinitionWithBuiltInClass<T> = T extends number
? NumberSchemaDefinition
: T extends string
? StringSchemaDefinition
: T extends boolean
? BooleanSchemaDefinition
: T extends NativeDate
? DateSchemaDefinition
: (Function | string);