mongoose 6.1.10 → 6.2.3
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 +154 -0
- package/CHANGELOG.md +73 -0
- package/dist/browser.umd.js +233 -222
- package/index.js +5 -1
- package/lib/aggregate.js +23 -28
- package/lib/browserDocument.js +1 -1
- package/lib/cast/number.js +2 -3
- package/lib/cast.js +9 -7
- package/lib/connection.js +76 -24
- package/lib/cursor/AggregationCursor.js +12 -7
- package/lib/cursor/QueryCursor.js +11 -6
- package/lib/document.js +131 -122
- package/lib/drivers/node-mongodb-native/collection.js +12 -4
- package/lib/drivers/node-mongodb-native/connection.js +11 -0
- package/lib/error/cast.js +3 -2
- package/lib/error/index.js +11 -0
- package/lib/error/syncIndexes.js +30 -0
- package/lib/helpers/clone.js +51 -29
- package/lib/helpers/common.js +2 -2
- package/lib/helpers/cursor/eachAsync.js +18 -15
- package/lib/helpers/document/compile.js +7 -4
- package/lib/helpers/getFunctionName.js +6 -4
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +14 -0
- package/lib/helpers/indexes/getRelatedIndexes.js +59 -0
- package/lib/helpers/isMongooseObject.js +9 -8
- package/lib/helpers/isObject.js +4 -4
- package/lib/helpers/model/discriminator.js +2 -1
- package/lib/helpers/path/parentPaths.js +10 -5
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -2
- package/lib/helpers/populate/assignVals.js +12 -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/printJestWarning.js +2 -2
- package/lib/helpers/projection/applyProjection.js +77 -0
- package/lib/helpers/projection/hasIncludedChildren.js +36 -0
- package/lib/helpers/projection/isExclusive.js +5 -2
- package/lib/helpers/projection/isInclusive.js +5 -1
- package/lib/helpers/query/cast$expr.js +279 -0
- package/lib/helpers/query/castUpdate.js +6 -2
- package/lib/helpers/query/hasDollarKeys.js +7 -3
- package/lib/helpers/query/isOperator.js +5 -2
- package/lib/helpers/schema/applyPlugins.js +11 -0
- package/lib/helpers/schema/getIndexes.js +6 -2
- package/lib/helpers/schema/getPath.js +4 -2
- package/lib/helpers/timestamps/setupTimestamps.js +3 -8
- package/lib/index.js +26 -19
- package/lib/internal.js +10 -2
- package/lib/model.js +196 -171
- package/lib/options/SchemaTypeOptions.js +1 -1
- package/lib/plugins/trackTransaction.js +5 -4
- package/lib/query.js +159 -146
- package/lib/queryhelpers.js +10 -10
- package/lib/schema/SubdocumentPath.js +4 -3
- package/lib/schema/array.js +30 -21
- package/lib/schema/buffer.js +1 -1
- package/lib/schema/date.js +1 -1
- package/lib/schema/decimal128.js +1 -1
- package/lib/schema/documentarray.js +9 -11
- package/lib/schema/number.js +1 -1
- package/lib/schema/objectid.js +2 -2
- package/lib/schema/string.js +4 -4
- package/lib/schema.js +13 -8
- package/lib/schematype.js +86 -40
- package/lib/types/ArraySubdocument.js +2 -1
- package/lib/types/DocumentArray/index.js +10 -27
- package/lib/types/DocumentArray/isMongooseDocumentArray.js +5 -0
- package/lib/types/DocumentArray/methods/index.js +15 -3
- package/lib/types/array/index.js +22 -21
- package/lib/types/array/isMongooseArray.js +5 -0
- package/lib/types/array/methods/index.js +22 -23
- package/lib/types/buffer.js +3 -3
- package/lib/types/map.js +3 -4
- package/lib/utils.js +19 -10
- package/package.json +34 -168
- package/tools/repl.js +1 -1
- package/tsconfig.json +8 -0
- package/types/Error.d.ts +129 -0
- package/types/PipelineStage.d.ts +272 -0
- package/{index.d.ts → types/index.d.ts} +169 -481
- package/lib/types/array/ArrayWrapper.js +0 -981
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/// <reference path="./Error.d.ts" />
|
|
2
|
+
/// <reference path="./PipelineStage.d.ts" />
|
|
3
|
+
|
|
4
|
+
import events = require('events');
|
|
5
|
+
import mongodb = require('mongodb');
|
|
6
|
+
import mongoose = require('mongoose');
|
|
7
|
+
import stream = require('stream');
|
|
8
|
+
|
|
1
9
|
declare module 'mongoose' {
|
|
2
|
-
import events = require('events');
|
|
3
|
-
import mongodb = require('mongodb');
|
|
4
|
-
import mongoose = require('mongoose');
|
|
5
|
-
import stream = require('stream');
|
|
6
10
|
|
|
7
11
|
export enum ConnectionStates {
|
|
8
12
|
disconnected = 0,
|
|
@@ -74,8 +78,8 @@ declare module 'mongoose' {
|
|
|
74
78
|
* the model's schema except the `_id` index, and build any indexes that
|
|
75
79
|
* are in your schema but not in MongoDB.
|
|
76
80
|
*/
|
|
77
|
-
export function syncIndexes(options?:
|
|
78
|
-
export function syncIndexes(options:
|
|
81
|
+
export function syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
|
|
82
|
+
export function syncIndexes(options: SyncIndexesOptions | null, callback: Callback<ConnectionSyncIndexesResult>): void;
|
|
79
83
|
|
|
80
84
|
/* Tells `sanitizeFilter()` to skip the given object when filtering out potential query selector injection attacks.
|
|
81
85
|
* Use this method when you have a known query selector that you want to use. */
|
|
@@ -114,13 +118,14 @@ declare module 'mongoose' {
|
|
|
114
118
|
/** Gets mongoose options */
|
|
115
119
|
export function get<K extends keyof MongooseOptions>(key: K): MongooseOptions[K];
|
|
116
120
|
|
|
117
|
-
|
|
121
|
+
/* ! ignore */
|
|
118
122
|
type CompileModelOptions = { overwriteModels?: boolean, connection?: Connection };
|
|
119
123
|
|
|
120
124
|
/**
|
|
121
125
|
* Returns true if Mongoose can cast the given value to an ObjectId, or
|
|
122
126
|
* false otherwise.
|
|
123
127
|
*/
|
|
128
|
+
export function isValidObjectId(v: Types.ObjectId): true;
|
|
124
129
|
export function isValidObjectId(v: any): boolean;
|
|
125
130
|
|
|
126
131
|
export function model<T>(name: string, schema?: Schema<T, any, any> | Schema<T & Document, any, any>, collection?: string, options?: CompileModelOptions): Model<T>;
|
|
@@ -165,6 +170,7 @@ declare module 'mongoose' {
|
|
|
165
170
|
export const version: string;
|
|
166
171
|
|
|
167
172
|
export type CastError = Error.CastError;
|
|
173
|
+
export type SyncIndexesError = Error.SyncIndexesError;
|
|
168
174
|
|
|
169
175
|
type Mongoose = typeof mongoose;
|
|
170
176
|
|
|
@@ -260,6 +266,9 @@ declare module 'mongoose' {
|
|
|
260
266
|
/** true by default, may be `false`, `true`, or `'throw'`. Sets the default strict mode for schemas. */
|
|
261
267
|
strict?: boolean | 'throw';
|
|
262
268
|
|
|
269
|
+
/** true by default. set to `false` to allow populating paths that aren't in the schema */
|
|
270
|
+
strictPopulate?: boolean;
|
|
271
|
+
|
|
263
272
|
/**
|
|
264
273
|
* false by default, may be `false`, `true`, or `'throw'`. Sets the default
|
|
265
274
|
* [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
|
|
@@ -304,7 +313,7 @@ declare module 'mongoose' {
|
|
|
304
313
|
close(force?: boolean): Promise<void>;
|
|
305
314
|
|
|
306
315
|
/** Retrieves a collection, creating it if not cached. */
|
|
307
|
-
collection(name: string, options?: mongodb.CreateCollectionOptions): Collection
|
|
316
|
+
collection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Collection<T>;
|
|
308
317
|
|
|
309
318
|
/** A hash of the collections associated with this connection */
|
|
310
319
|
collections: { [index: string]: Collection };
|
|
@@ -320,9 +329,9 @@ declare module 'mongoose' {
|
|
|
320
329
|
* with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
|
|
321
330
|
* and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
|
|
322
331
|
*/
|
|
323
|
-
createCollection(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection
|
|
324
|
-
createCollection(name: string, cb: Callback<mongodb.Collection
|
|
325
|
-
createCollection(name: string, options: mongodb.CreateCollectionOptions, cb?: Callback<mongodb.Collection
|
|
332
|
+
createCollection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
|
|
333
|
+
createCollection<T = AnyObject>(name: string, cb: Callback<mongodb.Collection<T>>): void;
|
|
334
|
+
createCollection<T = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, cb?: Callback<mongodb.Collection<T>>): Promise<mongodb.Collection<T>>;
|
|
326
335
|
|
|
327
336
|
/**
|
|
328
337
|
* Removes the model named `name` from this connection, if it exists. You can
|
|
@@ -442,8 +451,8 @@ declare module 'mongoose' {
|
|
|
442
451
|
* the model's schema except the `_id` index, and build any indexes that
|
|
443
452
|
* are in your schema but not in MongoDB.
|
|
444
453
|
*/
|
|
445
|
-
syncIndexes(options?:
|
|
446
|
-
syncIndexes(options:
|
|
454
|
+
syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
|
|
455
|
+
syncIndexes(options: SyncIndexesOptions | null, callback: Callback<ConnectionSyncIndexesResult>): void;
|
|
447
456
|
|
|
448
457
|
/**
|
|
449
458
|
* _Requires MongoDB >= 3.6.0._ Executes the wrapped async function
|
|
@@ -467,7 +476,7 @@ declare module 'mongoose' {
|
|
|
467
476
|
* section collection.js
|
|
468
477
|
* http://mongoosejs.com/docs/api.html#collection-js
|
|
469
478
|
*/
|
|
470
|
-
interface CollectionBase extends mongodb.Collection {
|
|
479
|
+
interface CollectionBase<T> extends mongodb.Collection<T> {
|
|
471
480
|
/*
|
|
472
481
|
* Abstract methods. Some of these are already defined on the
|
|
473
482
|
* mongodb.Collection interface so they've been commented out.
|
|
@@ -489,7 +498,7 @@ declare module 'mongoose' {
|
|
|
489
498
|
* http://mongoosejs.com/docs/api.html#drivers-node-mongodb-native-collection-js
|
|
490
499
|
*/
|
|
491
500
|
let Collection: Collection;
|
|
492
|
-
interface Collection extends CollectionBase {
|
|
501
|
+
interface Collection<T = AnyObject> extends CollectionBase<T> {
|
|
493
502
|
/**
|
|
494
503
|
* Collection constructor
|
|
495
504
|
* @param name name of the collection
|
|
@@ -497,7 +506,7 @@ declare module 'mongoose' {
|
|
|
497
506
|
* @param opts optional collection options
|
|
498
507
|
*/
|
|
499
508
|
// eslint-disable-next-line @typescript-eslint/no-misused-new
|
|
500
|
-
new(name: string, conn: Connection, opts?: any): Collection
|
|
509
|
+
new(name: string, conn: Connection, opts?: any): Collection<T>;
|
|
501
510
|
/** Formatter for debug print args */
|
|
502
511
|
$format(arg: any): string;
|
|
503
512
|
/** Debug print helper */
|
|
@@ -759,7 +768,7 @@ declare module 'mongoose' {
|
|
|
759
768
|
|
|
760
769
|
type Require_id<T> = T extends { _id?: any } ? (T & { _id: T['_id'] }) : (T & { _id: Types.ObjectId });
|
|
761
770
|
|
|
762
|
-
export type HydratedDocument<DocType,
|
|
771
|
+
export type HydratedDocument<DocType, TMethodsAndOverrides = {}, TVirtuals = {}> = DocType extends Document ? Require_id<DocType> : (Document<unknown, any, DocType> & Require_id<DocType> & TVirtuals & TMethodsAndOverrides);
|
|
763
772
|
|
|
764
773
|
interface IndexesDiff {
|
|
765
774
|
/** Indexes that would be created in mongodb. */
|
|
@@ -768,9 +777,15 @@ declare module 'mongoose' {
|
|
|
768
777
|
toDrop: Array<any>
|
|
769
778
|
}
|
|
770
779
|
|
|
780
|
+
interface ModifyResult<T> {
|
|
781
|
+
value: Require_id<T> | null;
|
|
782
|
+
lastErrorObject?: mongodb.Document;
|
|
783
|
+
ok: 0 | 1;
|
|
784
|
+
}
|
|
785
|
+
|
|
771
786
|
export const Model: Model<any>;
|
|
772
|
-
interface Model<T, TQueryHelpers = {},
|
|
773
|
-
new<DocType = AnyKeys<T> & AnyObject>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T,
|
|
787
|
+
interface Model<T, TQueryHelpers = {}, TMethodsAndOverrides = {}, TVirtuals = {}> extends NodeJS.EventEmitter, AcceptsDiscriminator {
|
|
788
|
+
new<DocType = AnyKeys<T> & AnyObject>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
|
|
774
789
|
|
|
775
790
|
aggregate<R = any>(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
|
|
776
791
|
aggregate<R = any>(pipeline: PipelineStage[], cb: Function): Aggregate<Array<R>>;
|
|
@@ -799,37 +814,37 @@ declare module 'mongoose' {
|
|
|
799
814
|
* sending multiple `save()` calls because with `bulkSave()` there is only one
|
|
800
815
|
* network round trip to the MongoDB server.
|
|
801
816
|
*/
|
|
802
|
-
bulkSave(documents: Array<Document
|
|
817
|
+
bulkSave(documents: Array<Document>, options?: mongodb.BulkWriteOptions): Promise<mongodb.BulkWriteResult>;
|
|
803
818
|
|
|
804
819
|
/** Collection the model uses. */
|
|
805
820
|
collection: Collection;
|
|
806
821
|
|
|
807
822
|
/** Creates a `count` query: counts the number of documents that match `filter`. */
|
|
808
|
-
count(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
809
|
-
count(filter: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
823
|
+
count(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
824
|
+
count(filter: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
810
825
|
|
|
811
826
|
/** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
|
|
812
|
-
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
813
|
-
countDocuments(filter: FilterQuery<T>, options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
827
|
+
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
828
|
+
countDocuments(filter: FilterQuery<T>, options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
814
829
|
|
|
815
830
|
/** Creates a new document or documents */
|
|
816
|
-
create(docs: (AnyKeys<T> | AnyObject)[], options?: SaveOptions): Promise<HydratedDocument<T,
|
|
817
|
-
create(docs: (AnyKeys<T> | AnyObject)[], callback: Callback<HydratedDocument<T,
|
|
818
|
-
create(doc: AnyKeys<T> | AnyObject): Promise<HydratedDocument<T,
|
|
819
|
-
create(doc: AnyKeys<T> | AnyObject, callback: Callback<HydratedDocument<T,
|
|
820
|
-
create<DocContents = AnyKeys<T>>(docs: DocContents[], options?: SaveOptions): Promise<HydratedDocument<T,
|
|
821
|
-
create<DocContents = AnyKeys<T>>(docs: DocContents[], callback: Callback<HydratedDocument<T,
|
|
822
|
-
create<DocContents = AnyKeys<T>>(doc: DocContents): Promise<HydratedDocument<T,
|
|
823
|
-
create<DocContents = AnyKeys<T>>(...docs: DocContents[]): Promise<HydratedDocument<T,
|
|
824
|
-
create<DocContents = AnyKeys<T>>(doc: DocContents, callback: Callback<HydratedDocument<T,
|
|
831
|
+
create(docs: (AnyKeys<T> | AnyObject)[], options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
832
|
+
create(docs: (AnyKeys<T> | AnyObject)[], callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
|
|
833
|
+
create(doc: AnyKeys<T> | AnyObject): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
834
|
+
create(doc: AnyKeys<T> | AnyObject, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
|
|
835
|
+
create<DocContents = AnyKeys<T>>(docs: DocContents[], options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
836
|
+
create<DocContents = AnyKeys<T>>(docs: DocContents[], callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
|
|
837
|
+
create<DocContents = AnyKeys<T>>(doc: DocContents): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
838
|
+
create<DocContents = AnyKeys<T>>(...docs: DocContents[]): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
839
|
+
create<DocContents = AnyKeys<T>>(doc: DocContents, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
|
|
825
840
|
|
|
826
841
|
/**
|
|
827
842
|
* Create the collection for this model. By default, if no indexes are specified,
|
|
828
843
|
* mongoose will not create the collection for the model until any documents are
|
|
829
844
|
* created. Use this method to create the collection explicitly.
|
|
830
845
|
*/
|
|
831
|
-
createCollection(options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection
|
|
832
|
-
createCollection(options: mongodb.CreateCollectionOptions | null, callback: Callback<mongodb.Collection
|
|
846
|
+
createCollection<T>(options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
|
|
847
|
+
createCollection<T>(options: mongodb.CreateCollectionOptions | null, callback: Callback<mongodb.Collection<T>>): void;
|
|
833
848
|
|
|
834
849
|
/**
|
|
835
850
|
* Similar to `ensureIndexes()`, except for it uses the [`createIndex`](http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#createIndex)
|
|
@@ -846,18 +861,18 @@ declare module 'mongoose' {
|
|
|
846
861
|
* Behaves like `remove()`, but deletes all documents that match `conditions`
|
|
847
862
|
* regardless of the `single` option.
|
|
848
863
|
*/
|
|
849
|
-
deleteMany(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
850
|
-
deleteMany(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
851
|
-
deleteMany(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
864
|
+
deleteMany(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
865
|
+
deleteMany(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
866
|
+
deleteMany(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
852
867
|
|
|
853
868
|
/**
|
|
854
869
|
* Deletes the first document that matches `conditions` from the collection.
|
|
855
870
|
* Behaves like `remove()`, but deletes at most one document regardless of the
|
|
856
871
|
* `single` option.
|
|
857
872
|
*/
|
|
858
|
-
deleteOne(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
859
|
-
deleteOne(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
860
|
-
deleteOne(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T,
|
|
873
|
+
deleteOne(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
874
|
+
deleteOne(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
875
|
+
deleteOne(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
861
876
|
|
|
862
877
|
/**
|
|
863
878
|
* Sends `createIndex` commands to mongo for each index declared in the schema.
|
|
@@ -877,16 +892,16 @@ declare module 'mongoose' {
|
|
|
877
892
|
* equivalent to `findOne({ _id: id })`. If you want to query by a document's
|
|
878
893
|
* `_id`, use `findById()` instead of `findOne()`.
|
|
879
894
|
*/
|
|
880
|
-
findById(id: any, projection?: any | null, options?: QueryOptions | null, callback?: Callback<
|
|
895
|
+
findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: any, projection?: any | null, options?: QueryOptions | null, callback?: Callback<ResultDoc | null>): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
881
896
|
|
|
882
897
|
/** Finds one document. */
|
|
883
|
-
findOne(filter?: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: Callback<
|
|
898
|
+
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>;
|
|
884
899
|
|
|
885
900
|
/**
|
|
886
901
|
* Shortcut for creating a new Document from existing raw data, pre-saved in the DB.
|
|
887
902
|
* The document returned has no paths marked as modified initially.
|
|
888
903
|
*/
|
|
889
|
-
hydrate(obj: any): HydratedDocument<T,
|
|
904
|
+
hydrate(obj: any): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
|
|
890
905
|
|
|
891
906
|
/**
|
|
892
907
|
* This function is responsible for building [indexes](https://docs.mongodb.com/manual/indexes/),
|
|
@@ -896,15 +911,15 @@ declare module 'mongoose' {
|
|
|
896
911
|
* [`connection.model()`](/docs/api.html#connection_Connection-model), so you
|
|
897
912
|
* don't need to call it.
|
|
898
913
|
*/
|
|
899
|
-
init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T,
|
|
914
|
+
init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
900
915
|
|
|
901
916
|
/** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
|
|
902
|
-
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult
|
|
903
|
-
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions): Promise<Array<HydratedDocument<T,
|
|
904
|
-
insertMany(doc: AnyKeys<T> | AnyObject, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult
|
|
905
|
-
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions): Promise<HydratedDocument<T,
|
|
906
|
-
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T,
|
|
907
|
-
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T,
|
|
917
|
+
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult<T>>;
|
|
918
|
+
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
|
|
919
|
+
insertMany(doc: AnyKeys<T> | AnyObject, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult<T>>;
|
|
920
|
+
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
921
|
+
insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[] | InsertManyResult<T>>): void;
|
|
922
|
+
insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>> | InsertManyResult<T>>): void;
|
|
908
923
|
|
|
909
924
|
/**
|
|
910
925
|
* Lists the indexes currently defined in MongoDB. This may or may not be
|
|
@@ -920,9 +935,9 @@ declare module 'mongoose' {
|
|
|
920
935
|
|
|
921
936
|
/** Populates document references. */
|
|
922
937
|
populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
|
|
923
|
-
callback?: Callback<(HydratedDocument<T,
|
|
938
|
+
callback?: Callback<(HydratedDocument<T, TMethodsAndOverrides, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
|
|
924
939
|
populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string,
|
|
925
|
-
callback?: Callback<HydratedDocument<T,
|
|
940
|
+
callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
926
941
|
|
|
927
942
|
/**
|
|
928
943
|
* Makes the indexes in MongoDB match the indexes defined in this model's
|
|
@@ -957,7 +972,7 @@ declare module 'mongoose' {
|
|
|
957
972
|
watch<ResultType = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
|
|
958
973
|
|
|
959
974
|
/** Adds a `$where` clause to this query */
|
|
960
|
-
$where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T,
|
|
975
|
+
$where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
961
976
|
|
|
962
977
|
/** Registered discriminators for this model. */
|
|
963
978
|
discriminators: { [name: string]: Model<any> } | undefined;
|
|
@@ -966,51 +981,51 @@ declare module 'mongoose' {
|
|
|
966
981
|
translateAliases(raw: any): any;
|
|
967
982
|
|
|
968
983
|
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
|
|
969
|
-
distinct(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<any>, HydratedDocument<T,
|
|
984
|
+
distinct(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<any>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
970
985
|
|
|
971
986
|
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
|
|
972
|
-
estimatedDocumentCount(options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T,
|
|
987
|
+
estimatedDocumentCount(options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
973
988
|
|
|
974
989
|
/**
|
|
975
|
-
* Returns
|
|
976
|
-
* the given `filter`, and
|
|
990
|
+
* Returns a document with its `_id` if at least one document exists in the database that matches
|
|
991
|
+
* the given `filter`, and `null` otherwise.
|
|
977
992
|
*/
|
|
978
|
-
exists(filter: FilterQuery<T>):
|
|
979
|
-
exists(filter: FilterQuery<T>, callback: Callback<
|
|
993
|
+
exists(filter: FilterQuery<T>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
994
|
+
exists(filter: FilterQuery<T>, callback: Callback<Pick<Document<T>, '_id'> | null>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
980
995
|
|
|
981
996
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
982
|
-
find
|
|
983
|
-
find(filter: FilterQuery<T>, callback?: Callback<
|
|
984
|
-
find(filter: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: Callback<
|
|
997
|
+
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
998
|
+
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
999
|
+
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
985
1000
|
|
|
986
1001
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
987
|
-
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc:
|
|
1002
|
+
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>;
|
|
988
1003
|
|
|
989
1004
|
/** Creates a `findByIdAndRemove` query, filtering by the given `_id`. */
|
|
990
|
-
findByIdAndRemove(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc:
|
|
1005
|
+
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>;
|
|
991
1006
|
|
|
992
1007
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
993
|
-
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<
|
|
994
|
-
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc:
|
|
995
|
-
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc:
|
|
996
|
-
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<T>, callback: (err: CallbackError, doc:
|
|
1008
|
+
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>;
|
|
1009
|
+
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>;
|
|
1010
|
+
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>;
|
|
1011
|
+
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>;
|
|
997
1012
|
|
|
998
1013
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
999
|
-
findOneAndDelete(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc:
|
|
1014
|
+
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>;
|
|
1000
1015
|
|
|
1001
1016
|
/** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
|
|
1002
|
-
findOneAndRemove(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc:
|
|
1017
|
+
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>;
|
|
1003
1018
|
|
|
1004
1019
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
1005
|
-
findOneAndReplace(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc:
|
|
1006
|
-
findOneAndReplace(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: (err: CallbackError, doc:
|
|
1020
|
+
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>;
|
|
1021
|
+
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>;
|
|
1007
1022
|
|
|
1008
1023
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
1009
|
-
findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<
|
|
1010
|
-
findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc:
|
|
1011
|
-
findOneAndUpdate(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: T | null, res: any) => void): QueryWithHelpers<
|
|
1024
|
+
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>;
|
|
1025
|
+
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>;
|
|
1026
|
+
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>;
|
|
1012
1027
|
|
|
1013
|
-
geoSearch(filter?: FilterQuery<T>, options?: GeoSearchOptions, callback?: Callback<Array<
|
|
1028
|
+
geoSearch<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: GeoSearchOptions, callback?: Callback<Array<ResultDoc>>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1014
1029
|
|
|
1015
1030
|
/** Executes a mapReduce command. */
|
|
1016
1031
|
mapReduce<Key, Value>(
|
|
@@ -1018,11 +1033,11 @@ declare module 'mongoose' {
|
|
|
1018
1033
|
callback?: Callback
|
|
1019
1034
|
): Promise<any>;
|
|
1020
1035
|
|
|
1021
|
-
remove(filter?: any, callback?: CallbackWithoutResult): QueryWithHelpers<any,
|
|
1036
|
+
remove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: any, callback?: CallbackWithoutResult): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
1022
1037
|
|
|
1023
1038
|
/** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
|
|
1024
|
-
replaceOne(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any,
|
|
1025
|
-
replaceOne(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any,
|
|
1039
|
+
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
1040
|
+
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
1026
1041
|
|
|
1027
1042
|
/** Schema the model uses. */
|
|
1028
1043
|
schema: Schema<T>;
|
|
@@ -1031,18 +1046,18 @@ declare module 'mongoose' {
|
|
|
1031
1046
|
* @deprecated use `updateOne` or `updateMany` instead.
|
|
1032
1047
|
* Creates a `update` query: updates one or many documents that match `filter` with `update`, based on the `multi` option.
|
|
1033
1048
|
*/
|
|
1034
|
-
update(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult,
|
|
1049
|
+
update<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
1035
1050
|
|
|
1036
1051
|
/** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
|
|
1037
|
-
updateMany(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult,
|
|
1052
|
+
updateMany<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
1038
1053
|
|
|
1039
1054
|
/** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
|
|
1040
|
-
updateOne(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult,
|
|
1055
|
+
updateOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
1041
1056
|
|
|
1042
1057
|
/** Creates a Query, applies the passed conditions, and returns the Query. */
|
|
1043
|
-
where(path: string, val?: any): QueryWithHelpers<Array<
|
|
1044
|
-
where(obj: object): QueryWithHelpers<Array<
|
|
1045
|
-
where
|
|
1058
|
+
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(path: string, val?: any): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1059
|
+
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(obj: object): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1060
|
+
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
1046
1061
|
}
|
|
1047
1062
|
|
|
1048
1063
|
type UpdateWriteOpResult = mongodb.UpdateResult;
|
|
@@ -1155,9 +1170,13 @@ declare module 'mongoose' {
|
|
|
1155
1170
|
populate?: string | string[] | PopulateOptions | PopulateOptions[];
|
|
1156
1171
|
}
|
|
1157
1172
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1173
|
+
type InferIdType<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
|
|
1174
|
+
type InsertManyResult<T> = mongodb.InsertManyResult<T> & {
|
|
1175
|
+
insertedIds: {
|
|
1176
|
+
[key: number]: InferIdType<T>;
|
|
1177
|
+
};
|
|
1178
|
+
mongoose?: { validationErrors?: Array<Error.CastError | Error.ValidatorError> };
|
|
1179
|
+
};
|
|
1161
1180
|
|
|
1162
1181
|
interface MapReduceOptions<T, Key, Val> {
|
|
1163
1182
|
map: Function | string;
|
|
@@ -1363,7 +1382,9 @@ declare module 'mongoose' {
|
|
|
1363
1382
|
|
|
1364
1383
|
/** Defines a pre hook for the model. */
|
|
1365
1384
|
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', fn: PreSaveMiddlewareFunction<T>): this;
|
|
1385
|
+
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', options: SchemaPreOptions, fn: PreSaveMiddlewareFunction<T>): this;
|
|
1366
1386
|
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
|
|
1387
|
+
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
|
|
1367
1388
|
pre<T extends Query<any, any>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
|
|
1368
1389
|
pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PreMiddlewareFunction<T>): this;
|
|
1369
1390
|
pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
|
|
@@ -1408,6 +1429,7 @@ declare module 'mongoose' {
|
|
|
1408
1429
|
type StringSchemaDefinition = typeof String | 'string' | 'String' | typeof Schema.Types.String;
|
|
1409
1430
|
type BooleanSchemaDefinition = typeof Boolean | 'boolean' | 'Boolean' | typeof Schema.Types.Boolean;
|
|
1410
1431
|
type DateSchemaDefinition = typeof NativeDate | 'date' | 'Date' | typeof Schema.Types.Date;
|
|
1432
|
+
type ObjectIdSchemaDefinition = 'ObjectId' | 'ObjectID' | typeof Schema.Types.ObjectId;
|
|
1411
1433
|
|
|
1412
1434
|
type SchemaDefinitionWithBuiltInClass<T> = T extends number
|
|
1413
1435
|
? NumberSchemaDefinition
|
|
@@ -1505,6 +1527,11 @@ declare module 'mongoose' {
|
|
|
1505
1527
|
* optimistic concurrency.
|
|
1506
1528
|
*/
|
|
1507
1529
|
optimisticConcurrency?: boolean;
|
|
1530
|
+
/**
|
|
1531
|
+
* If `plugin()` called with tags, Mongoose will only apply plugins to schemas that have
|
|
1532
|
+
* a matching tag in `pluginTags`
|
|
1533
|
+
*/
|
|
1534
|
+
pluginTags?: string[];
|
|
1508
1535
|
/**
|
|
1509
1536
|
* Allows setting query#read options at the schema level, providing us a way to apply default ReadPreferences
|
|
1510
1537
|
* to all queries derived from a model.
|
|
@@ -1581,6 +1608,13 @@ declare module 'mongoose' {
|
|
|
1581
1608
|
* field names by setting timestamps.createdAt and timestamps.updatedAt.
|
|
1582
1609
|
*/
|
|
1583
1610
|
timestamps?: boolean | SchemaTimestampsConfig;
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* Using `save`, `isNew`, and other Mongoose reserved names as schema path names now triggers a warning, not an error.
|
|
1614
|
+
* You can suppress the warning by setting { supressReservedKeysWarning: true } schema options. Keep in mind that this
|
|
1615
|
+
* can break plugins that rely on these reserved names.
|
|
1616
|
+
*/
|
|
1617
|
+
supressReservedKeysWarning?: boolean
|
|
1584
1618
|
}
|
|
1585
1619
|
|
|
1586
1620
|
interface SchemaTimestampsConfig {
|
|
@@ -1603,6 +1637,8 @@ declare module 'mongoose' {
|
|
|
1603
1637
|
T extends NativeDate ? DateSchemaDefinition :
|
|
1604
1638
|
T extends Map<any, any> ? SchemaDefinition<typeof Map> :
|
|
1605
1639
|
T extends Buffer ? SchemaDefinition<typeof Buffer> :
|
|
1640
|
+
T extends Types.ObjectId ? ObjectIdSchemaDefinition :
|
|
1641
|
+
T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId>> :
|
|
1606
1642
|
T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>>>) :
|
|
1607
1643
|
T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string>> :
|
|
1608
1644
|
T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number>> :
|
|
@@ -1808,6 +1844,8 @@ declare module 'mongoose' {
|
|
|
1808
1844
|
validator: ValidateFn<T> | LegacyAsyncValidateFn<T> | AsyncValidateFn<T>;
|
|
1809
1845
|
}
|
|
1810
1846
|
|
|
1847
|
+
type InferId<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
|
|
1848
|
+
|
|
1811
1849
|
interface VirtualTypeOptions {
|
|
1812
1850
|
/** If `ref` is not nullish, this becomes a populated virtual. */
|
|
1813
1851
|
ref?: string | Function;
|
|
@@ -2076,17 +2114,17 @@ declare module 'mongoose' {
|
|
|
2076
2114
|
|
|
2077
2115
|
class Decimal128 extends mongodb.Decimal128 { }
|
|
2078
2116
|
|
|
2079
|
-
class DocumentArray<T> extends Types.Array<T> {
|
|
2117
|
+
class DocumentArray<T> extends Types.Array<T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T> {
|
|
2080
2118
|
/** DocumentArray constructor */
|
|
2081
2119
|
constructor(values: any[]);
|
|
2082
2120
|
|
|
2083
2121
|
isMongooseDocumentArray: true;
|
|
2084
2122
|
|
|
2085
2123
|
/** Creates a subdocument casted to this schema. */
|
|
2086
|
-
create(obj: any): T;
|
|
2124
|
+
create(obj: any): T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T;
|
|
2087
2125
|
|
|
2088
2126
|
/** Searches array items for the first document with a matching _id. */
|
|
2089
|
-
id(id: any): T | null;
|
|
2127
|
+
id(id: any): (T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T) | null;
|
|
2090
2128
|
|
|
2091
2129
|
push(...args: (AnyKeys<T> & AnyObject)[]): number;
|
|
2092
2130
|
}
|
|
@@ -2126,6 +2164,8 @@ declare module 'mongoose' {
|
|
|
2126
2164
|
type UnpackedIntersection<T, U> = T extends (infer V)[] ? (V & U)[] : T & U;
|
|
2127
2165
|
type UnpackedIntersectionWithNull<T, U> = T extends null ? UnpackedIntersection<T, U> | null : UnpackedIntersection<T, U>;
|
|
2128
2166
|
|
|
2167
|
+
type ProjectionFields<DocType> = {[Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any} & Record<string, any>;
|
|
2168
|
+
|
|
2129
2169
|
class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {
|
|
2130
2170
|
_mongooseOptions: MongooseQueryOptions;
|
|
2131
2171
|
|
|
@@ -2269,9 +2309,24 @@ declare module 'mongoose' {
|
|
|
2269
2309
|
findOneAndRemove(filter?: FilterQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
2270
2310
|
|
|
2271
2311
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
2272
|
-
findOneAndUpdate(
|
|
2273
|
-
|
|
2274
|
-
|
|
2312
|
+
findOneAndUpdate(
|
|
2313
|
+
filter: FilterQuery<DocType>,
|
|
2314
|
+
update: UpdateQuery<DocType>,
|
|
2315
|
+
options: QueryOptions & { rawResult: true },
|
|
2316
|
+
callback?: (err: CallbackError, doc: DocType | null, res: ModifyResult<DocType>) => void
|
|
2317
|
+
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType>;
|
|
2318
|
+
findOneAndUpdate(
|
|
2319
|
+
filter: FilterQuery<DocType>,
|
|
2320
|
+
update: UpdateQuery<DocType>,
|
|
2321
|
+
options: QueryOptions & { upsert: true } & ReturnsNewDoc,
|
|
2322
|
+
callback?: (err: CallbackError, doc: DocType, res: ModifyResult<DocType>) => void
|
|
2323
|
+
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType>;
|
|
2324
|
+
findOneAndUpdate(
|
|
2325
|
+
filter?: FilterQuery<DocType>,
|
|
2326
|
+
update?: UpdateQuery<DocType>,
|
|
2327
|
+
options?: QueryOptions | null,
|
|
2328
|
+
callback?: (err: CallbackError, doc: DocType | null, res: ModifyResult<DocType>) => void
|
|
2329
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
2275
2330
|
|
|
2276
2331
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
2277
2332
|
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
@@ -2412,7 +2467,9 @@ declare module 'mongoose' {
|
|
|
2412
2467
|
populate<Paths = {}>(options: PopulateOptions | Array<PopulateOptions>): QueryWithHelpers<UnpackedIntersectionWithNull<ResultType, Paths>, DocType, THelpers, RawDocType>;
|
|
2413
2468
|
|
|
2414
2469
|
/** Get/set the current projection (AKA fields). Pass `null` to remove the current projection. */
|
|
2415
|
-
projection(
|
|
2470
|
+
projection(): ProjectionFields<DocType> | null;
|
|
2471
|
+
projection(fields: null): null;
|
|
2472
|
+
projection(fields?: ProjectionFields<DocType> | string): ProjectionFields<DocType>;
|
|
2416
2473
|
|
|
2417
2474
|
/** Determines the MongoDB nodes from which to read. */
|
|
2418
2475
|
read(pref: string | mongodb.ReadPreferenceMode, tags?: any[]): this;
|
|
@@ -2957,272 +3014,6 @@ declare module 'mongoose' {
|
|
|
2957
3014
|
next(callback: Callback): void;
|
|
2958
3015
|
}
|
|
2959
3016
|
|
|
2960
|
-
/**
|
|
2961
|
-
* [Stages reference](https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/#aggregation-pipeline-stages)
|
|
2962
|
-
*/
|
|
2963
|
-
export type PipelineStage =
|
|
2964
|
-
| PipelineStage.AddFields
|
|
2965
|
-
| PipelineStage.Bucket
|
|
2966
|
-
| PipelineStage.BucketAuto
|
|
2967
|
-
| PipelineStage.CollStats
|
|
2968
|
-
| PipelineStage.Count
|
|
2969
|
-
| PipelineStage.Facet
|
|
2970
|
-
| PipelineStage.GeoNear
|
|
2971
|
-
| PipelineStage.GraphLookup
|
|
2972
|
-
| PipelineStage.Group
|
|
2973
|
-
| PipelineStage.IndexStats
|
|
2974
|
-
| PipelineStage.Limit
|
|
2975
|
-
| PipelineStage.ListSessions
|
|
2976
|
-
| PipelineStage.Lookup
|
|
2977
|
-
| PipelineStage.Match
|
|
2978
|
-
| PipelineStage.Merge
|
|
2979
|
-
| PipelineStage.Out
|
|
2980
|
-
| PipelineStage.PlanCacheStats
|
|
2981
|
-
| PipelineStage.Project
|
|
2982
|
-
| PipelineStage.Redact
|
|
2983
|
-
| PipelineStage.ReplaceRoot
|
|
2984
|
-
| PipelineStage.ReplaceWith
|
|
2985
|
-
| PipelineStage.Sample
|
|
2986
|
-
| PipelineStage.Search
|
|
2987
|
-
| PipelineStage.Set
|
|
2988
|
-
| PipelineStage.SetWindowFields
|
|
2989
|
-
| PipelineStage.Skip
|
|
2990
|
-
| PipelineStage.Sort
|
|
2991
|
-
| PipelineStage.SortByCount
|
|
2992
|
-
| PipelineStage.UnionWith
|
|
2993
|
-
| PipelineStage.Unset
|
|
2994
|
-
| PipelineStage.Unwind
|
|
2995
|
-
|
|
2996
|
-
export namespace PipelineStage {
|
|
2997
|
-
export interface AddFields {
|
|
2998
|
-
/** [`$addFields` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/) */
|
|
2999
|
-
$addFields: Record<string, any>
|
|
3000
|
-
}
|
|
3001
|
-
|
|
3002
|
-
export interface Bucket {
|
|
3003
|
-
/** [`$bucket` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucket/) */
|
|
3004
|
-
$bucket: {
|
|
3005
|
-
groupBy: any
|
|
3006
|
-
boundaries: any[]
|
|
3007
|
-
default?: any
|
|
3008
|
-
output?: Record<string, { [op in AccumulatorOperator]?: any }>
|
|
3009
|
-
}
|
|
3010
|
-
}
|
|
3011
|
-
|
|
3012
|
-
export interface BucketAuto {
|
|
3013
|
-
/** [`$bucketAuto` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/) */
|
|
3014
|
-
$bucketAuto: {
|
|
3015
|
-
groupBy: any
|
|
3016
|
-
buckets: number
|
|
3017
|
-
output?: Record<string, { [op in AccumulatorOperator]?: any }>
|
|
3018
|
-
granularity?: 'R5' | 'R10' | 'R20' | 'R40' | 'R80' | '1-2-5' | 'E6' | 'E12' | 'E24' | 'E48' | 'E96' | 'E192' | 'POWERSOF2'
|
|
3019
|
-
}
|
|
3020
|
-
}
|
|
3021
|
-
|
|
3022
|
-
export interface CollStats {
|
|
3023
|
-
/** [`$collStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/collStats/) */
|
|
3024
|
-
$collStats: {
|
|
3025
|
-
latencyStats?: { histograms?: boolean }
|
|
3026
|
-
storageStats?: { scale?: number }
|
|
3027
|
-
count?: {}
|
|
3028
|
-
queryExecStats?: {}
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
|
|
3032
|
-
export interface Count {
|
|
3033
|
-
/** [`$count` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/count/) */
|
|
3034
|
-
$count: string
|
|
3035
|
-
}
|
|
3036
|
-
|
|
3037
|
-
export interface Facet {
|
|
3038
|
-
/** [`$facet` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/facet/) */
|
|
3039
|
-
$facet: Record<string, FacetPipelineStage[]>
|
|
3040
|
-
}
|
|
3041
|
-
|
|
3042
|
-
export type FacetPipelineStage = Exclude<PipelineStage, PipelineStage.CollStats | PipelineStage.Facet | PipelineStage.GeoNear | PipelineStage.IndexStats | PipelineStage.Out | PipelineStage.Merge | PipelineStage.PlanCacheStats>
|
|
3043
|
-
|
|
3044
|
-
export interface GeoNear {
|
|
3045
|
-
/** [`$geoNear` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/) */
|
|
3046
|
-
$geoNear: {
|
|
3047
|
-
near: { type: 'Point'; coordinates: [number, number] } | [number, number]
|
|
3048
|
-
distanceField: string
|
|
3049
|
-
distanceMultiplier?: number
|
|
3050
|
-
includeLocs?: string
|
|
3051
|
-
key?: string
|
|
3052
|
-
maxDistance?: number
|
|
3053
|
-
minDistance?: number
|
|
3054
|
-
query?: AnyObject
|
|
3055
|
-
spherical?: boolean
|
|
3056
|
-
uniqueDocs?: boolean
|
|
3057
|
-
}
|
|
3058
|
-
}
|
|
3059
|
-
|
|
3060
|
-
export interface GraphLookup {
|
|
3061
|
-
/** [`$graphLookup` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/) */
|
|
3062
|
-
$graphLookup: {
|
|
3063
|
-
from: string
|
|
3064
|
-
startWith: any
|
|
3065
|
-
connectFromField: string
|
|
3066
|
-
connectToField: string
|
|
3067
|
-
as: string
|
|
3068
|
-
maxDepth?: number
|
|
3069
|
-
depthField?: string
|
|
3070
|
-
restrictSearchWithMatch?: AnyObject
|
|
3071
|
-
}
|
|
3072
|
-
}
|
|
3073
|
-
|
|
3074
|
-
export interface Group {
|
|
3075
|
-
/** [`$group` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/group) */
|
|
3076
|
-
$group: { _id: any } | { [key: string]: { [op in AccumulatorOperator]?: any } }
|
|
3077
|
-
}
|
|
3078
|
-
|
|
3079
|
-
export interface IndexStats {
|
|
3080
|
-
/** [`$indexStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/) */
|
|
3081
|
-
$indexStats: {}
|
|
3082
|
-
}
|
|
3083
|
-
|
|
3084
|
-
export interface Limit {
|
|
3085
|
-
/** [`$limit` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/limit/) */
|
|
3086
|
-
$limit: number
|
|
3087
|
-
}
|
|
3088
|
-
|
|
3089
|
-
export interface ListSessions {
|
|
3090
|
-
/** [`$listSessions` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/listSessions/) */
|
|
3091
|
-
$listSessions: { users?: { user: string; db: string }[] } | { allUsers?: true }
|
|
3092
|
-
}
|
|
3093
|
-
|
|
3094
|
-
export interface Lookup {
|
|
3095
|
-
/** [`$lookup` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/) */
|
|
3096
|
-
$lookup: {
|
|
3097
|
-
from: string
|
|
3098
|
-
as: string
|
|
3099
|
-
localField?: string
|
|
3100
|
-
foreignField?: string
|
|
3101
|
-
let?: Record<string, any>
|
|
3102
|
-
pipeline?: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out | PipelineStage.Search>[]
|
|
3103
|
-
}
|
|
3104
|
-
}
|
|
3105
|
-
|
|
3106
|
-
export interface Match {
|
|
3107
|
-
/** [`$match` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) */
|
|
3108
|
-
$match: AnyObject
|
|
3109
|
-
}
|
|
3110
|
-
|
|
3111
|
-
export interface Merge {
|
|
3112
|
-
/** [`$merge` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/merge/) */
|
|
3113
|
-
$merge: {
|
|
3114
|
-
into: string | { db: string; coll: string }
|
|
3115
|
-
on?: string | string[]
|
|
3116
|
-
let?: Record<string, any>
|
|
3117
|
-
whenMatched?: 'replace' | 'keepExisting' | 'merge' | 'fail' | Extract<PipelineStage, PipelineStage.AddFields | PipelineStage.Set | PipelineStage.Project | PipelineStage.Unset | PipelineStage.ReplaceRoot | PipelineStage.ReplaceWith>[]
|
|
3118
|
-
whenNotMatched?: 'insert' | 'discard' | 'fail'
|
|
3119
|
-
}
|
|
3120
|
-
}
|
|
3121
|
-
|
|
3122
|
-
export interface Out {
|
|
3123
|
-
/** [`$out` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/out/) */
|
|
3124
|
-
$out: string | { db: string; coll: string }
|
|
3125
|
-
}
|
|
3126
|
-
|
|
3127
|
-
export interface PlanCacheStats {
|
|
3128
|
-
/** [`$planCacheStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/planCacheStats/) */
|
|
3129
|
-
$planCacheStats: {}
|
|
3130
|
-
}
|
|
3131
|
-
|
|
3132
|
-
export interface Project {
|
|
3133
|
-
/** [`$project` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/project/) */
|
|
3134
|
-
$project: { [field: string]: any }
|
|
3135
|
-
}
|
|
3136
|
-
|
|
3137
|
-
export interface Redact {
|
|
3138
|
-
/** [`$redact` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/redact/) */
|
|
3139
|
-
$redact: any
|
|
3140
|
-
}
|
|
3141
|
-
|
|
3142
|
-
export interface ReplaceRoot {
|
|
3143
|
-
/** [`$replaceRoot` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceRoot/) */
|
|
3144
|
-
$replaceRoot: { newRoot: any }
|
|
3145
|
-
}
|
|
3146
|
-
|
|
3147
|
-
export interface ReplaceWith {
|
|
3148
|
-
/** [`$replaceWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/) */
|
|
3149
|
-
$replaceWith: any
|
|
3150
|
-
}
|
|
3151
|
-
|
|
3152
|
-
export interface Sample {
|
|
3153
|
-
/** [`$sample` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sample/) */
|
|
3154
|
-
$sample: { size: number }
|
|
3155
|
-
}
|
|
3156
|
-
|
|
3157
|
-
export interface Search {
|
|
3158
|
-
/** [`$search` reference](https://docs.atlas.mongodb.com/reference/atlas-search/query-syntax/) */
|
|
3159
|
-
$search: {
|
|
3160
|
-
[key: string]: any
|
|
3161
|
-
index?: string
|
|
3162
|
-
highlight?: { path: string; maxCharsToExamine?: number; maxNumPassages?: number }
|
|
3163
|
-
}
|
|
3164
|
-
}
|
|
3165
|
-
|
|
3166
|
-
export interface Set {
|
|
3167
|
-
/** [`$set` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/set/) */
|
|
3168
|
-
$set: Record<string, any>
|
|
3169
|
-
}
|
|
3170
|
-
|
|
3171
|
-
export interface SetWindowFields {
|
|
3172
|
-
/** [`$setWindowFields` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/setWindowFields/) */
|
|
3173
|
-
$setWindowFields: {
|
|
3174
|
-
partitionBy?: any
|
|
3175
|
-
sortBy?: Record<string, 1 | -1>
|
|
3176
|
-
output: Record<
|
|
3177
|
-
string,
|
|
3178
|
-
{ [op in WindowOperator]?: any } & {
|
|
3179
|
-
window?: {
|
|
3180
|
-
documents?: [string | number, string | number]
|
|
3181
|
-
range?: [string | number, string | number]
|
|
3182
|
-
unit?: 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond'
|
|
3183
|
-
}
|
|
3184
|
-
}
|
|
3185
|
-
>
|
|
3186
|
-
}
|
|
3187
|
-
}
|
|
3188
|
-
|
|
3189
|
-
export interface Skip {
|
|
3190
|
-
/** [`$skip` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/skip/) */
|
|
3191
|
-
$skip: number
|
|
3192
|
-
}
|
|
3193
|
-
|
|
3194
|
-
export interface Sort {
|
|
3195
|
-
/** [`$sort` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sort/) */
|
|
3196
|
-
$sort: Record<string, 1 | -1 | { $meta: 'textScore' }>
|
|
3197
|
-
}
|
|
3198
|
-
|
|
3199
|
-
export interface SortByCount {
|
|
3200
|
-
/** [`$sortByCount` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sortByCount/) */
|
|
3201
|
-
$sortByCount: any
|
|
3202
|
-
}
|
|
3203
|
-
|
|
3204
|
-
export interface UnionWith {
|
|
3205
|
-
/** [`$unionWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unionWith/) */
|
|
3206
|
-
$unionWith:
|
|
3207
|
-
| string
|
|
3208
|
-
| { coll: string; pipeline?: Exclude<PipelineStage, PipelineStage.Out | PipelineStage.Merge>[] }
|
|
3209
|
-
}
|
|
3210
|
-
|
|
3211
|
-
export interface Unset {
|
|
3212
|
-
/** [`$unset` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unset/) */
|
|
3213
|
-
$unset: string | string[]
|
|
3214
|
-
}
|
|
3215
|
-
|
|
3216
|
-
export interface Unwind {
|
|
3217
|
-
/** [`$unwind` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/) */
|
|
3218
|
-
$unwind: string | { path: string; includeArrayIndex?: string; preserveNullAndEmptyArrays?: boolean }
|
|
3219
|
-
}
|
|
3220
|
-
|
|
3221
|
-
type AccumulatorOperator = '$accumulator' | '$addToSet' | '$avg' | '$count' | '$first' | '$last' | '$max' | '$mergeObjects' | '$min' | '$push' | '$stdDevPop' | '$stdDevSamp' | '$sum'
|
|
3222
|
-
|
|
3223
|
-
type WindowOperator = '$addToSet' | '$avg' | '$count' | '$covariancePop' | '$covarianceSamp' | '$derivative' | '$expMovingAvg' | '$integral' | '$max' | '$min' | '$push' | '$stdDevSamp' | '$stdDevPop' | '$sum' | '$first' | '$last' | '$shift' | '$denseRank' | '$documentNumber' | '$rank'
|
|
3224
|
-
}
|
|
3225
|
-
|
|
3226
3017
|
class SchemaType {
|
|
3227
3018
|
/** SchemaType constructor */
|
|
3228
3019
|
constructor(path: string, options?: AnyObject, instance?: string);
|
|
@@ -3262,9 +3053,15 @@ declare module 'mongoose' {
|
|
|
3262
3053
|
/** String representation of what type this is, like 'ObjectID' or 'Number' */
|
|
3263
3054
|
instance: string;
|
|
3264
3055
|
|
|
3056
|
+
/** True if this SchemaType has a required validator. False otherwise. */
|
|
3057
|
+
isRequired?: boolean;
|
|
3058
|
+
|
|
3265
3059
|
/** The options this SchemaType was instantiated with */
|
|
3266
3060
|
options: AnyObject;
|
|
3267
3061
|
|
|
3062
|
+
/** The path to this SchemaType in a Schema. */
|
|
3063
|
+
path: string;
|
|
3064
|
+
|
|
3268
3065
|
/**
|
|
3269
3066
|
* Set the model that this path refers to. This is the option that [populate](https://mongoosejs.com/docs/populate.html)
|
|
3270
3067
|
* looks at to determine the foreign collection it should query.
|
|
@@ -3298,134 +3095,25 @@ declare module 'mongoose' {
|
|
|
3298
3095
|
/** Declares an unique index. */
|
|
3299
3096
|
unique(bool: boolean): this;
|
|
3300
3097
|
|
|
3098
|
+
/** The validators that Mongoose should run to validate properties at this SchemaType's path. */
|
|
3099
|
+
validators: { message?: string; type?: string; validator?: Function }[];
|
|
3100
|
+
|
|
3301
3101
|
/** Adds validator(s) for this document path. */
|
|
3302
3102
|
validate(obj: RegExp | Function | any, errorMsg?: string,
|
|
3303
3103
|
type?: string): this;
|
|
3304
3104
|
}
|
|
3305
3105
|
|
|
3106
|
+
export interface SyncIndexesOptions extends mongodb.CreateIndexesOptions {
|
|
3107
|
+
continueOnError?: boolean
|
|
3108
|
+
}
|
|
3109
|
+
export type ConnectionSyncIndexesResult = Record<string, OneCollectionSyncIndexesResult>;
|
|
3110
|
+
type OneCollectionSyncIndexesResult = Array<string> & mongodb.MongoServerError;
|
|
3306
3111
|
type Callback<T = any> = (error: CallbackError, result: T) => void;
|
|
3307
3112
|
|
|
3308
3113
|
type CallbackWithoutResult = (error: CallbackError) => void;
|
|
3309
3114
|
|
|
3310
|
-
class NativeError extends global.Error { }
|
|
3311
|
-
type CallbackError = NativeError | null;
|
|
3312
|
-
|
|
3313
|
-
class Error extends global.Error {
|
|
3314
|
-
constructor(msg: string);
|
|
3315
|
-
|
|
3316
|
-
/** The type of error. "MongooseError" for generic errors. */
|
|
3317
|
-
name: string;
|
|
3318
|
-
|
|
3319
|
-
static messages: any;
|
|
3320
|
-
|
|
3321
|
-
static Messages: any;
|
|
3322
|
-
}
|
|
3323
|
-
|
|
3324
|
-
namespace Error {
|
|
3325
|
-
export class CastError extends Error {
|
|
3326
|
-
name: 'CastError';
|
|
3327
|
-
stringValue: string;
|
|
3328
|
-
kind: string;
|
|
3329
|
-
value: any;
|
|
3330
|
-
path: string;
|
|
3331
|
-
reason?: NativeError | null;
|
|
3332
|
-
model?: any;
|
|
3333
|
-
|
|
3334
|
-
constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
|
|
3335
|
-
}
|
|
3336
|
-
|
|
3337
|
-
export class DisconnectedError extends Error {
|
|
3338
|
-
name: 'DisconnectedError';
|
|
3339
|
-
}
|
|
3340
|
-
|
|
3341
|
-
export class DivergentArrayError extends Error {
|
|
3342
|
-
name: 'DivergentArrayError';
|
|
3343
|
-
}
|
|
3344
|
-
|
|
3345
|
-
export class MissingSchemaError extends Error {
|
|
3346
|
-
name: 'MissingSchemaError';
|
|
3347
|
-
}
|
|
3348
|
-
|
|
3349
|
-
export class DocumentNotFoundError extends Error {
|
|
3350
|
-
name: 'DocumentNotFoundError';
|
|
3351
|
-
result: any;
|
|
3352
|
-
numAffected: number;
|
|
3353
|
-
filter: any;
|
|
3354
|
-
query: any;
|
|
3355
|
-
}
|
|
3356
|
-
|
|
3357
|
-
export class ObjectExpectedError extends Error {
|
|
3358
|
-
name: 'ObjectExpectedError';
|
|
3359
|
-
path: string;
|
|
3360
|
-
}
|
|
3361
|
-
|
|
3362
|
-
export class ObjectParameterError extends Error {
|
|
3363
|
-
name: 'ObjectParameterError';
|
|
3364
|
-
}
|
|
3365
|
-
|
|
3366
|
-
export class OverwriteModelError extends Error {
|
|
3367
|
-
name: 'OverwriteModelError';
|
|
3368
|
-
}
|
|
3369
|
-
|
|
3370
|
-
export class ParallelSaveError extends Error {
|
|
3371
|
-
name: 'ParallelSaveError';
|
|
3372
|
-
}
|
|
3373
|
-
|
|
3374
|
-
export class ParallelValidateError extends Error {
|
|
3375
|
-
name: 'ParallelValidateError';
|
|
3376
|
-
}
|
|
3377
|
-
|
|
3378
|
-
export class MongooseServerSelectionError extends Error {
|
|
3379
|
-
name: 'MongooseServerSelectionError';
|
|
3380
|
-
}
|
|
3381
|
-
|
|
3382
|
-
export class StrictModeError extends Error {
|
|
3383
|
-
name: 'StrictModeError';
|
|
3384
|
-
isImmutableError: boolean;
|
|
3385
|
-
path: string;
|
|
3386
|
-
}
|
|
3387
|
-
|
|
3388
|
-
export class ValidationError extends Error {
|
|
3389
|
-
name: 'ValidationError';
|
|
3390
|
-
|
|
3391
|
-
errors: { [path: string]: ValidatorError | CastError | ValidationError };
|
|
3392
|
-
addError: (path: string, error: ValidatorError | CastError | ValidationError) => void;
|
|
3393
|
-
|
|
3394
|
-
constructor(instance?: Error);
|
|
3395
|
-
}
|
|
3396
|
-
|
|
3397
|
-
export class ValidatorError extends Error {
|
|
3398
|
-
name: 'ValidatorError';
|
|
3399
|
-
properties: {
|
|
3400
|
-
message: string,
|
|
3401
|
-
type?: string,
|
|
3402
|
-
path?: string,
|
|
3403
|
-
value?: any,
|
|
3404
|
-
reason?: any
|
|
3405
|
-
};
|
|
3406
|
-
kind: string;
|
|
3407
|
-
path: string;
|
|
3408
|
-
value: any;
|
|
3409
|
-
reason?: Error | null;
|
|
3410
|
-
|
|
3411
|
-
constructor(properties: {
|
|
3412
|
-
message?: string,
|
|
3413
|
-
type?: string,
|
|
3414
|
-
path?: string,
|
|
3415
|
-
value?: any,
|
|
3416
|
-
reason?: any
|
|
3417
|
-
});
|
|
3418
|
-
}
|
|
3419
|
-
|
|
3420
|
-
export class VersionError extends Error {
|
|
3421
|
-
name: 'VersionError';
|
|
3422
|
-
version: number;
|
|
3423
|
-
modifiedPaths: Array<string>;
|
|
3424
|
-
|
|
3425
|
-
constructor(doc: Document, currentVersion: number, modifiedPaths: Array<string>);
|
|
3426
|
-
}
|
|
3427
|
-
}
|
|
3428
|
-
|
|
3429
3115
|
/* for ts-mongoose */
|
|
3430
3116
|
class mquery {}
|
|
3431
3117
|
}
|
|
3118
|
+
|
|
3119
|
+
export default mongoose;
|