mongoose 6.2.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +150 -0
- package/CHANGELOG.md +21 -0
- package/dist/browser.umd.js +113 -112
- package/lib/aggregate.js +1 -1
- package/lib/document.js +83 -64
- package/lib/helpers/clone.js +40 -27
- package/lib/helpers/common.js +2 -2
- package/lib/helpers/getFunctionName.js +6 -4
- package/lib/helpers/isMongooseObject.js +9 -8
- package/lib/helpers/isObject.js +4 -4
- package/lib/helpers/path/parentPaths.js +10 -5
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -2
- package/lib/helpers/populate/assignVals.js +8 -4
- package/lib/helpers/populate/getModelsMapForPopulate.js +4 -4
- package/lib/helpers/populate/markArraySubdocsPopulated.js +3 -1
- package/lib/helpers/populate/modelNamesFromRefPath.js +4 -3
- package/lib/helpers/query/castUpdate.js +6 -2
- package/lib/helpers/schema/getPath.js +4 -2
- package/lib/helpers/timestamps/setupTimestamps.js +3 -8
- package/lib/index.js +2 -0
- package/lib/internal.js +1 -1
- package/lib/model.js +22 -8
- package/lib/plugins/trackTransaction.js +4 -3
- package/lib/query.js +3 -2
- package/lib/queryhelpers.js +1 -1
- package/lib/schema/array.js +17 -15
- package/lib/schema/documentarray.js +5 -8
- package/lib/schema/objectid.js +1 -1
- package/lib/schematype.js +29 -26
- package/lib/types/ArraySubdocument.js +2 -1
- package/lib/types/DocumentArray/index.js +9 -26
- package/lib/types/DocumentArray/isMongooseDocumentArray.js +5 -0
- package/lib/types/DocumentArray/methods/index.js +15 -3
- package/lib/types/array/index.js +21 -20
- package/lib/types/array/isMongooseArray.js +5 -0
- package/lib/types/array/methods/index.js +12 -12
- package/lib/utils.js +7 -0
- package/package.json +18 -147
- package/tools/repl.js +1 -1
- package/tsconfig.json +10 -0
- package/{index.d.ts → types/index.d.ts} +84 -75
|
@@ -121,6 +121,7 @@ declare module 'mongoose' {
|
|
|
121
121
|
* Returns true if Mongoose can cast the given value to an ObjectId, or
|
|
122
122
|
* false otherwise.
|
|
123
123
|
*/
|
|
124
|
+
export function isValidObjectId(v: Types.ObjectId): true;
|
|
124
125
|
export function isValidObjectId(v: any): boolean;
|
|
125
126
|
|
|
126
127
|
export function model<T>(name: string, schema?: Schema<T, any, any> | Schema<T & Document, any, any>, collection?: string, options?: CompileModelOptions): Model<T>;
|
|
@@ -261,6 +262,9 @@ declare module 'mongoose' {
|
|
|
261
262
|
/** true by default, may be `false`, `true`, or `'throw'`. Sets the default strict mode for schemas. */
|
|
262
263
|
strict?: boolean | 'throw';
|
|
263
264
|
|
|
265
|
+
/** true by default. set to `false` to allow populating paths that aren't in the schema */
|
|
266
|
+
strictPopulate?: boolean;
|
|
267
|
+
|
|
264
268
|
/**
|
|
265
269
|
* false by default, may be `false`, `true`, or `'throw'`. Sets the default
|
|
266
270
|
* [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
|
|
@@ -305,7 +309,7 @@ declare module 'mongoose' {
|
|
|
305
309
|
close(force?: boolean): Promise<void>;
|
|
306
310
|
|
|
307
311
|
/** Retrieves a collection, creating it if not cached. */
|
|
308
|
-
collection(name: string, options?: mongodb.CreateCollectionOptions): Collection
|
|
312
|
+
collection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Collection<T>;
|
|
309
313
|
|
|
310
314
|
/** A hash of the collections associated with this connection */
|
|
311
315
|
collections: { [index: string]: Collection };
|
|
@@ -321,9 +325,9 @@ declare module 'mongoose' {
|
|
|
321
325
|
* with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
|
|
322
326
|
* and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
|
|
323
327
|
*/
|
|
324
|
-
createCollection(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection
|
|
325
|
-
createCollection(name: string, cb: Callback<mongodb.Collection
|
|
326
|
-
createCollection(name: string, options: mongodb.CreateCollectionOptions, cb?: Callback<mongodb.Collection
|
|
328
|
+
createCollection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
|
|
329
|
+
createCollection<T = AnyObject>(name: string, cb: Callback<mongodb.Collection<T>>): void;
|
|
330
|
+
createCollection<T = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, cb?: Callback<mongodb.Collection<T>>): Promise<mongodb.Collection<T>>;
|
|
327
331
|
|
|
328
332
|
/**
|
|
329
333
|
* Removes the model named `name` from this connection, if it exists. You can
|
|
@@ -468,7 +472,7 @@ declare module 'mongoose' {
|
|
|
468
472
|
* section collection.js
|
|
469
473
|
* http://mongoosejs.com/docs/api.html#collection-js
|
|
470
474
|
*/
|
|
471
|
-
interface CollectionBase extends mongodb.Collection {
|
|
475
|
+
interface CollectionBase<T> extends mongodb.Collection<T> {
|
|
472
476
|
/*
|
|
473
477
|
* Abstract methods. Some of these are already defined on the
|
|
474
478
|
* mongodb.Collection interface so they've been commented out.
|
|
@@ -490,7 +494,7 @@ declare module 'mongoose' {
|
|
|
490
494
|
* http://mongoosejs.com/docs/api.html#drivers-node-mongodb-native-collection-js
|
|
491
495
|
*/
|
|
492
496
|
let Collection: Collection;
|
|
493
|
-
interface Collection extends CollectionBase {
|
|
497
|
+
interface Collection<T = AnyObject> extends CollectionBase<T> {
|
|
494
498
|
/**
|
|
495
499
|
* Collection constructor
|
|
496
500
|
* @param name name of the collection
|
|
@@ -498,7 +502,7 @@ declare module 'mongoose' {
|
|
|
498
502
|
* @param opts optional collection options
|
|
499
503
|
*/
|
|
500
504
|
// eslint-disable-next-line @typescript-eslint/no-misused-new
|
|
501
|
-
new(name: string, conn: Connection, opts?: any): Collection
|
|
505
|
+
new(name: string, conn: Connection, opts?: any): Collection<T>;
|
|
502
506
|
/** Formatter for debug print args */
|
|
503
507
|
$format(arg: any): string;
|
|
504
508
|
/** Debug print helper */
|
|
@@ -760,7 +764,7 @@ declare module 'mongoose' {
|
|
|
760
764
|
|
|
761
765
|
type Require_id<T> = T extends { _id?: any } ? (T & { _id: T['_id'] }) : (T & { _id: Types.ObjectId });
|
|
762
766
|
|
|
763
|
-
export type HydratedDocument<DocType,
|
|
767
|
+
export type HydratedDocument<DocType, TMethodsAndOverrides = {}, TVirtuals = {}> = DocType extends Document ? Require_id<DocType> : (Document<unknown, any, DocType> & Require_id<DocType> & TVirtuals & TMethodsAndOverrides);
|
|
764
768
|
|
|
765
769
|
interface IndexesDiff {
|
|
766
770
|
/** Indexes that would be created in mongodb. */
|
|
@@ -776,8 +780,8 @@ declare module 'mongoose' {
|
|
|
776
780
|
}
|
|
777
781
|
|
|
778
782
|
export const Model: Model<any>;
|
|
779
|
-
interface Model<T, TQueryHelpers = {},
|
|
780
|
-
new<DocType = AnyKeys<T> & AnyObject>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T,
|
|
783
|
+
interface Model<T, TQueryHelpers = {}, TMethodsAndOverrides = {}, TVirtuals = {}> extends NodeJS.EventEmitter, AcceptsDiscriminator {
|
|
784
|
+
new<DocType = AnyKeys<T> & AnyObject>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
|
|
781
785
|
|
|
782
786
|
aggregate<R = any>(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
|
|
783
787
|
aggregate<R = any>(pipeline: PipelineStage[], cb: Function): Aggregate<Array<R>>;
|
|
@@ -812,31 +816,31 @@ declare module 'mongoose' {
|
|
|
812
816
|
collection: Collection;
|
|
813
817
|
|
|
814
818
|
/** Creates a `count` query: counts the number of documents that match `filter`. */
|
|
815
|
-
count(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
816
|
-
count(filter: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
819
|
+
count(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
820
|
+
count(filter: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
817
821
|
|
|
818
822
|
/** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
|
|
819
|
-
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
820
|
-
countDocuments(filter: FilterQuery<T>, options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
823
|
+
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
824
|
+
countDocuments(filter: FilterQuery<T>, options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
821
825
|
|
|
822
826
|
/** Creates a new document or documents */
|
|
823
|
-
create(docs: (AnyKeys<T> | AnyObject)[], options?: SaveOptions): Promise<HydratedDocument<T,
|
|
824
|
-
create(docs: (AnyKeys<T> | AnyObject)[], callback: Callback<HydratedDocument<T,
|
|
825
|
-
create(doc: AnyKeys<T> | AnyObject): Promise<HydratedDocument<T,
|
|
826
|
-
create(doc: AnyKeys<T> | AnyObject, callback: Callback<HydratedDocument<T,
|
|
827
|
-
create<DocContents = AnyKeys<T>>(docs: DocContents[], options?: SaveOptions): Promise<HydratedDocument<T,
|
|
828
|
-
create<DocContents = AnyKeys<T>>(docs: DocContents[], callback: Callback<HydratedDocument<T,
|
|
829
|
-
create<DocContents = AnyKeys<T>>(doc: DocContents): Promise<HydratedDocument<T,
|
|
830
|
-
create<DocContents = AnyKeys<T>>(...docs: DocContents[]): Promise<HydratedDocument<T,
|
|
831
|
-
create<DocContents = AnyKeys<T>>(doc: DocContents, callback: Callback<HydratedDocument<T,
|
|
827
|
+
create(docs: (AnyKeys<T> | AnyObject)[], options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
828
|
+
create(docs: (AnyKeys<T> | AnyObject)[], callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
|
|
829
|
+
create(doc: AnyKeys<T> | AnyObject): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
830
|
+
create(doc: AnyKeys<T> | AnyObject, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
|
|
831
|
+
create<DocContents = AnyKeys<T>>(docs: DocContents[], options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
832
|
+
create<DocContents = AnyKeys<T>>(docs: DocContents[], callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
|
|
833
|
+
create<DocContents = AnyKeys<T>>(doc: DocContents): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
834
|
+
create<DocContents = AnyKeys<T>>(...docs: DocContents[]): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
835
|
+
create<DocContents = AnyKeys<T>>(doc: DocContents, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
|
|
832
836
|
|
|
833
837
|
/**
|
|
834
838
|
* Create the collection for this model. By default, if no indexes are specified,
|
|
835
839
|
* mongoose will not create the collection for the model until any documents are
|
|
836
840
|
* created. Use this method to create the collection explicitly.
|
|
837
841
|
*/
|
|
838
|
-
createCollection(options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection
|
|
839
|
-
createCollection(options: mongodb.CreateCollectionOptions | null, callback: Callback<mongodb.Collection
|
|
842
|
+
createCollection<T>(options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
|
|
843
|
+
createCollection<T>(options: mongodb.CreateCollectionOptions | null, callback: Callback<mongodb.Collection<T>>): void;
|
|
840
844
|
|
|
841
845
|
/**
|
|
842
846
|
* Similar to `ensureIndexes()`, except for it uses the [`createIndex`](http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#createIndex)
|
|
@@ -853,18 +857,18 @@ declare module 'mongoose' {
|
|
|
853
857
|
* Behaves like `remove()`, but deletes all documents that match `conditions`
|
|
854
858
|
* regardless of the `single` option.
|
|
855
859
|
*/
|
|
856
|
-
deleteMany(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
857
|
-
deleteMany(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
858
|
-
deleteMany(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
860
|
+
deleteMany(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
861
|
+
deleteMany(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
862
|
+
deleteMany(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
859
863
|
|
|
860
864
|
/**
|
|
861
865
|
* Deletes the first document that matches `conditions` from the collection.
|
|
862
866
|
* Behaves like `remove()`, but deletes at most one document regardless of the
|
|
863
867
|
* `single` option.
|
|
864
868
|
*/
|
|
865
|
-
deleteOne(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
866
|
-
deleteOne(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
867
|
-
deleteOne(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
869
|
+
deleteOne(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
870
|
+
deleteOne(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
871
|
+
deleteOne(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
868
872
|
|
|
869
873
|
/**
|
|
870
874
|
* Sends `createIndex` commands to mongo for each index declared in the schema.
|
|
@@ -884,16 +888,16 @@ declare module 'mongoose' {
|
|
|
884
888
|
* equivalent to `findOne({ _id: id })`. If you want to query by a document's
|
|
885
889
|
* `_id`, use `findById()` instead of `findOne()`.
|
|
886
890
|
*/
|
|
887
|
-
findById<ResultDoc = HydratedDocument<T,
|
|
891
|
+
findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: any, projection?: any | null, options?: QueryOptions | null, callback?: Callback<ResultDoc | null>): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
888
892
|
|
|
889
893
|
/** Finds one document. */
|
|
890
|
-
findOne<ResultDoc = HydratedDocument<T,
|
|
894
|
+
findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: Callback<ResultDoc | null>): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
891
895
|
|
|
892
896
|
/**
|
|
893
897
|
* Shortcut for creating a new Document from existing raw data, pre-saved in the DB.
|
|
894
898
|
* The document returned has no paths marked as modified initially.
|
|
895
899
|
*/
|
|
896
|
-
hydrate(obj: any): HydratedDocument<T,
|
|
900
|
+
hydrate(obj: any): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
|
|
897
901
|
|
|
898
902
|
/**
|
|
899
903
|
* This function is responsible for building [indexes](https://docs.mongodb.com/manual/indexes/),
|
|
@@ -903,15 +907,15 @@ declare module 'mongoose' {
|
|
|
903
907
|
* [`connection.model()`](/docs/api.html#connection_Connection-model), so you
|
|
904
908
|
* don't need to call it.
|
|
905
909
|
*/
|
|
906
|
-
init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T,
|
|
910
|
+
init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
907
911
|
|
|
908
912
|
/** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
|
|
909
913
|
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
|
|
910
|
-
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions): Promise<Array<HydratedDocument<T,
|
|
914
|
+
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
|
|
911
915
|
insertMany(doc: AnyKeys<T> | AnyObject, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
|
|
912
|
-
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions): Promise<HydratedDocument<T,
|
|
913
|
-
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T,
|
|
914
|
-
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T,
|
|
916
|
+
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
917
|
+
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[] | InsertManyResult>): void;
|
|
918
|
+
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>> | InsertManyResult>): void;
|
|
915
919
|
|
|
916
920
|
/**
|
|
917
921
|
* Lists the indexes currently defined in MongoDB. This may or may not be
|
|
@@ -927,9 +931,9 @@ declare module 'mongoose' {
|
|
|
927
931
|
|
|
928
932
|
/** Populates document references. */
|
|
929
933
|
populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
|
|
930
|
-
callback?: Callback<(HydratedDocument<T,
|
|
934
|
+
callback?: Callback<(HydratedDocument<T, TMethodsAndOverrides, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
|
|
931
935
|
populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string,
|
|
932
|
-
callback?: Callback<HydratedDocument<T,
|
|
936
|
+
callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
933
937
|
|
|
934
938
|
/**
|
|
935
939
|
* Makes the indexes in MongoDB match the indexes defined in this model's
|
|
@@ -964,7 +968,7 @@ declare module 'mongoose' {
|
|
|
964
968
|
watch<ResultType = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
|
|
965
969
|
|
|
966
970
|
/** Adds a `$where` clause to this query */
|
|
967
|
-
$where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T,
|
|
971
|
+
$where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
968
972
|
|
|
969
973
|
/** Registered discriminators for this model. */
|
|
970
974
|
discriminators: { [name: string]: Model<any> } | undefined;
|
|
@@ -973,51 +977,51 @@ declare module 'mongoose' {
|
|
|
973
977
|
translateAliases(raw: any): any;
|
|
974
978
|
|
|
975
979
|
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
|
|
976
|
-
distinct(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<any>, HydratedDocument<T,
|
|
980
|
+
distinct(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<any>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
977
981
|
|
|
978
982
|
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
|
|
979
|
-
estimatedDocumentCount(options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
983
|
+
estimatedDocumentCount(options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
980
984
|
|
|
981
985
|
/**
|
|
982
986
|
* Returns a document with its `_id` if at least one document exists in the database that matches
|
|
983
987
|
* the given `filter`, and `null` otherwise.
|
|
984
988
|
*/
|
|
985
|
-
exists(filter: FilterQuery<T>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T,
|
|
986
|
-
exists(filter: FilterQuery<T>, callback: Callback<Pick<Document<T>, '_id'> | null>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T,
|
|
989
|
+
exists(filter: FilterQuery<T>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
990
|
+
exists(filter: FilterQuery<T>, callback: Callback<Pick<Document<T>, '_id'> | null>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
987
991
|
|
|
988
992
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
989
|
-
find<ResultDoc = HydratedDocument<T,
|
|
990
|
-
find<ResultDoc = HydratedDocument<T,
|
|
991
|
-
find<ResultDoc = HydratedDocument<T,
|
|
993
|
+
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
994
|
+
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
995
|
+
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
992
996
|
|
|
993
997
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
994
|
-
findByIdAndDelete<ResultDoc = HydratedDocument<T,
|
|
998
|
+
findByIdAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
995
999
|
|
|
996
1000
|
/** Creates a `findByIdAndRemove` query, filtering by the given `_id`. */
|
|
997
|
-
findByIdAndRemove<ResultDoc = HydratedDocument<T,
|
|
1001
|
+
findByIdAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
998
1002
|
|
|
999
1003
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
1000
|
-
findByIdAndUpdate<ResultDoc = HydratedDocument<T,
|
|
1001
|
-
findByIdAndUpdate<ResultDoc = HydratedDocument<T,
|
|
1002
|
-
findByIdAndUpdate<ResultDoc = HydratedDocument<T,
|
|
1003
|
-
findByIdAndUpdate<ResultDoc = HydratedDocument<T,
|
|
1004
|
+
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1005
|
+
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
|
|
1006
|
+
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
1007
|
+
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>;
|
|
1004
1008
|
|
|
1005
1009
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
1006
|
-
findOneAndDelete<ResultDoc = HydratedDocument<T,
|
|
1010
|
+
findOneAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
1007
1011
|
|
|
1008
1012
|
/** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
|
|
1009
|
-
findOneAndRemove<ResultDoc = HydratedDocument<T,
|
|
1013
|
+
findOneAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
1010
1014
|
|
|
1011
1015
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
1012
|
-
findOneAndReplace<ResultDoc = HydratedDocument<T,
|
|
1013
|
-
findOneAndReplace<ResultDoc = HydratedDocument<T,
|
|
1016
|
+
findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
|
|
1017
|
+
findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
1014
1018
|
|
|
1015
1019
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
1016
|
-
findOneAndUpdate<ResultDoc = HydratedDocument<T,
|
|
1017
|
-
findOneAndUpdate<ResultDoc = HydratedDocument<T,
|
|
1018
|
-
findOneAndUpdate<ResultDoc = HydratedDocument<T,
|
|
1020
|
+
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1021
|
+
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
|
|
1022
|
+
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: T | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
1019
1023
|
|
|
1020
|
-
geoSearch<ResultDoc = HydratedDocument<T,
|
|
1024
|
+
geoSearch<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: GeoSearchOptions, callback?: Callback<Array<ResultDoc>>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1021
1025
|
|
|
1022
1026
|
/** Executes a mapReduce command. */
|
|
1023
1027
|
mapReduce<Key, Value>(
|
|
@@ -1025,11 +1029,11 @@ declare module 'mongoose' {
|
|
|
1025
1029
|
callback?: Callback
|
|
1026
1030
|
): Promise<any>;
|
|
1027
1031
|
|
|
1028
|
-
remove<ResultDoc = HydratedDocument<T,
|
|
1032
|
+
remove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: any, callback?: CallbackWithoutResult): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
1029
1033
|
|
|
1030
1034
|
/** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
|
|
1031
|
-
replaceOne<ResultDoc = HydratedDocument<T,
|
|
1032
|
-
replaceOne<ResultDoc = HydratedDocument<T,
|
|
1035
|
+
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
1036
|
+
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
1033
1037
|
|
|
1034
1038
|
/** Schema the model uses. */
|
|
1035
1039
|
schema: Schema<T>;
|
|
@@ -1038,18 +1042,18 @@ declare module 'mongoose' {
|
|
|
1038
1042
|
* @deprecated use `updateOne` or `updateMany` instead.
|
|
1039
1043
|
* Creates a `update` query: updates one or many documents that match `filter` with `update`, based on the `multi` option.
|
|
1040
1044
|
*/
|
|
1041
|
-
update<ResultDoc = HydratedDocument<T,
|
|
1045
|
+
update<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
1042
1046
|
|
|
1043
1047
|
/** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
|
|
1044
|
-
updateMany<ResultDoc = HydratedDocument<T,
|
|
1048
|
+
updateMany<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
1045
1049
|
|
|
1046
1050
|
/** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
|
|
1047
|
-
updateOne<ResultDoc = HydratedDocument<T,
|
|
1051
|
+
updateOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
1048
1052
|
|
|
1049
1053
|
/** Creates a Query, applies the passed conditions, and returns the Query. */
|
|
1050
|
-
where<ResultDoc = HydratedDocument<T,
|
|
1051
|
-
where<ResultDoc = HydratedDocument<T,
|
|
1052
|
-
where<ResultDoc = HydratedDocument<T,
|
|
1054
|
+
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(path: string, val?: any): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1055
|
+
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(obj: object): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1056
|
+
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1053
1057
|
}
|
|
1054
1058
|
|
|
1055
1059
|
type UpdateWriteOpResult = mongodb.UpdateResult;
|
|
@@ -1415,6 +1419,7 @@ declare module 'mongoose' {
|
|
|
1415
1419
|
type StringSchemaDefinition = typeof String | 'string' | 'String' | typeof Schema.Types.String;
|
|
1416
1420
|
type BooleanSchemaDefinition = typeof Boolean | 'boolean' | 'Boolean' | typeof Schema.Types.Boolean;
|
|
1417
1421
|
type DateSchemaDefinition = typeof NativeDate | 'date' | 'Date' | typeof Schema.Types.Date;
|
|
1422
|
+
type ObjectIdSchemaDefinition = 'ObjectId' | 'ObjectID' | typeof Schema.Types.ObjectId;
|
|
1418
1423
|
|
|
1419
1424
|
type SchemaDefinitionWithBuiltInClass<T> = T extends number
|
|
1420
1425
|
? NumberSchemaDefinition
|
|
@@ -1615,6 +1620,8 @@ declare module 'mongoose' {
|
|
|
1615
1620
|
T extends NativeDate ? DateSchemaDefinition :
|
|
1616
1621
|
T extends Map<any, any> ? SchemaDefinition<typeof Map> :
|
|
1617
1622
|
T extends Buffer ? SchemaDefinition<typeof Buffer> :
|
|
1623
|
+
T extends Types.ObjectId ? ObjectIdSchemaDefinition :
|
|
1624
|
+
T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId>> :
|
|
1618
1625
|
T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>>>) :
|
|
1619
1626
|
T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string>> :
|
|
1620
1627
|
T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number>> :
|
|
@@ -1820,6 +1827,8 @@ declare module 'mongoose' {
|
|
|
1820
1827
|
validator: ValidateFn<T> | LegacyAsyncValidateFn<T> | AsyncValidateFn<T>;
|
|
1821
1828
|
}
|
|
1822
1829
|
|
|
1830
|
+
type InferId<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
|
|
1831
|
+
|
|
1823
1832
|
interface VirtualTypeOptions {
|
|
1824
1833
|
/** If `ref` is not nullish, this becomes a populated virtual. */
|
|
1825
1834
|
ref?: string | Function;
|
|
@@ -2088,17 +2097,17 @@ declare module 'mongoose' {
|
|
|
2088
2097
|
|
|
2089
2098
|
class Decimal128 extends mongodb.Decimal128 { }
|
|
2090
2099
|
|
|
2091
|
-
class DocumentArray<T> extends Types.Array<T> {
|
|
2100
|
+
class DocumentArray<T> extends Types.Array<T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T> {
|
|
2092
2101
|
/** DocumentArray constructor */
|
|
2093
2102
|
constructor(values: any[]);
|
|
2094
2103
|
|
|
2095
2104
|
isMongooseDocumentArray: true;
|
|
2096
2105
|
|
|
2097
2106
|
/** Creates a subdocument casted to this schema. */
|
|
2098
|
-
create(obj: any): T;
|
|
2107
|
+
create(obj: any): T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T;
|
|
2099
2108
|
|
|
2100
2109
|
/** Searches array items for the first document with a matching _id. */
|
|
2101
|
-
id(id: any): T | null;
|
|
2110
|
+
id(id: any): (T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T) | null;
|
|
2102
2111
|
|
|
2103
2112
|
push(...args: (AnyKeys<T> & AnyObject)[]): number;
|
|
2104
2113
|
}
|