mongoose 9.9.4 → 9.10.0
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/eslint.config.mjs +1 -0
- package/lib/aggregate.js +11 -4
- package/lib/cursor/aggregationCursor.js +19 -3
- package/lib/cursor/queryCursor.js +17 -5
- package/lib/document.js +10 -0
- package/lib/helpers/buildMiddlewareFilter.js +21 -3
- package/lib/helpers/model/applyHooks.js +9 -2
- package/lib/helpers/model/applyStaticHooks.js +9 -1
- package/lib/helpers/projection/isPathSelectedInclusive.js +1 -11
- package/lib/helpers/query/cast$expr.js +1 -1
- package/lib/model.js +47 -5
- package/lib/query.js +7 -1
- package/lib/schema/array.js +9 -1
- package/lib/schema/documentArray.js +2 -2
- package/lib/schema/subdocument.js +2 -2
- package/lib/schema.js +55 -0
- package/lib/schemaType.js +10 -4
- package/package.json +8 -8
- package/types/aggregate.d.ts +14 -1
- package/types/document.d.ts +2 -2
- package/types/index.d.ts +56 -8
- package/types/indexes.d.ts +73 -0
- package/types/middlewares.d.ts +11 -2
- package/types/models.d.ts +317 -1
- package/types/utility.d.ts +40 -0
package/types/aggregate.d.ts
CHANGED
|
@@ -10,6 +10,19 @@ declare module 'mongoose' {
|
|
|
10
10
|
[key: string]: any;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
interface AggregateCursorMiddlewareOptions {
|
|
14
|
+
/** If `false`, skip pre aggregate middleware. Aggregate cursors do not run post aggregate middleware. */
|
|
15
|
+
pre?: boolean;
|
|
16
|
+
post?: never;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface AggregateCursorOptions extends Omit<mongodb.AggregationCursorOptions & mongodb.Abortable, 'session'>, SessionOption {
|
|
20
|
+
middleware?: boolean | AggregateCursorMiddlewareOptions;
|
|
21
|
+
transform?: (doc: any) => any;
|
|
22
|
+
useMongooseAggCursor?: boolean;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
class Aggregate<ResultType> implements SessionOperation {
|
|
14
27
|
/**
|
|
15
28
|
* Returns an asyncIterator for use with [`for/await/of` loops](https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js)
|
|
@@ -62,7 +75,7 @@ declare module 'mongoose' {
|
|
|
62
75
|
/**
|
|
63
76
|
* Sets the cursor option for the aggregation query
|
|
64
77
|
*/
|
|
65
|
-
cursor<DocType = any>(options?:
|
|
78
|
+
cursor<DocType = any>(options?: AggregateCursorOptions): Cursor<DocType>;
|
|
66
79
|
|
|
67
80
|
|
|
68
81
|
/** Executes the aggregate pipeline on the currently bound Model. */
|
package/types/document.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ declare module 'mongoose' {
|
|
|
96
96
|
|
|
97
97
|
/** Returns the model with the given name on this document's associated connection. */
|
|
98
98
|
$model<ModelType extends Model<unknown>>(name: string): ModelType;
|
|
99
|
-
$model<ModelType extends Model<DocType>>(): ModelType;
|
|
99
|
+
$model<ModelType extends Model<DocType, any, any, any>>(): ModelType;
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* A string containing the current operation that Mongoose is executing
|
|
@@ -232,7 +232,7 @@ declare module 'mongoose' {
|
|
|
232
232
|
|
|
233
233
|
/** Returns the model with the given name on this document's associated connection. */
|
|
234
234
|
model<ModelType extends Model<unknown>>(name: string): ModelType;
|
|
235
|
-
model<ModelType extends Model<DocType>>(): ModelType;
|
|
235
|
+
model<ModelType extends Model<DocType, any, any, any>>(): ModelType;
|
|
236
236
|
|
|
237
237
|
/** Returns the list of paths that have been modified. */
|
|
238
238
|
modifiedPaths(options?: { includeChildren?: boolean }): Array<string>;
|
package/types/index.d.ts
CHANGED
|
@@ -493,6 +493,24 @@ declare module 'mongoose' {
|
|
|
493
493
|
method<Context = THydratedDocumentType>(name: string, fn: (this: Context, ...args: any[]) => any, opts?: any): this;
|
|
494
494
|
method(obj: Partial<TInstanceMethods>): this;
|
|
495
495
|
|
|
496
|
+
/** Adds a query helper to this schema. */
|
|
497
|
+
queryHelper<Name extends string, Fn extends (this: QueryWithHelpers<any, DocType, TQueryHelpers, RawDocType>, ...args: any[]) => any>(
|
|
498
|
+
name: Name,
|
|
499
|
+
fn: Fn
|
|
500
|
+
): Schema<
|
|
501
|
+
RawDocType,
|
|
502
|
+
TModelType,
|
|
503
|
+
TInstanceMethods,
|
|
504
|
+
TQueryHelpers & { [K in Name]: Fn },
|
|
505
|
+
TVirtuals,
|
|
506
|
+
TStaticMethods,
|
|
507
|
+
TSchemaOptions,
|
|
508
|
+
DocType,
|
|
509
|
+
THydratedDocumentType,
|
|
510
|
+
TSchemaDefinition,
|
|
511
|
+
LeanResultType
|
|
512
|
+
>;
|
|
513
|
+
|
|
496
514
|
/** Object of currently defined methods on this schema. */
|
|
497
515
|
methods: AddThisParameter<TInstanceMethods, THydratedDocumentType> & AnyObject;
|
|
498
516
|
|
|
@@ -667,12 +685,41 @@ declare module 'mongoose' {
|
|
|
667
685
|
|
|
668
686
|
/** Adds static "class" methods to Models compiled from this schema. */
|
|
669
687
|
static<K extends keyof TStaticMethods>(name: K, fn: TStaticMethods[K]): this;
|
|
670
|
-
static
|
|
671
|
-
|
|
688
|
+
static<Fns extends Partial<TStaticMethods> & { [name: string]: (this: TModelType, ...args: any[]) => any }>(
|
|
689
|
+
obj: Fns
|
|
690
|
+
): Schema<
|
|
691
|
+
RawDocType,
|
|
692
|
+
TModelType,
|
|
693
|
+
TInstanceMethods,
|
|
694
|
+
TQueryHelpers,
|
|
695
|
+
TVirtuals,
|
|
696
|
+
TStaticMethods & Fns,
|
|
697
|
+
TSchemaOptions,
|
|
698
|
+
DocType,
|
|
699
|
+
THydratedDocumentType,
|
|
700
|
+
TSchemaDefinition,
|
|
701
|
+
LeanResultType
|
|
702
|
+
>;
|
|
703
|
+
static<Name extends string, Fn extends (this: TModelType, ...args: any[]) => any>(
|
|
704
|
+
name: Name,
|
|
705
|
+
fn: Fn
|
|
706
|
+
): Schema<
|
|
707
|
+
RawDocType,
|
|
708
|
+
TModelType,
|
|
709
|
+
TInstanceMethods,
|
|
710
|
+
TQueryHelpers,
|
|
711
|
+
TVirtuals,
|
|
712
|
+
TStaticMethods & { [K in Name]: Fn },
|
|
713
|
+
TSchemaOptions,
|
|
714
|
+
DocType,
|
|
715
|
+
THydratedDocumentType,
|
|
716
|
+
TSchemaDefinition,
|
|
717
|
+
LeanResultType
|
|
718
|
+
>;
|
|
672
719
|
|
|
673
720
|
/** Object of currently defined statics on this schema. */
|
|
674
721
|
statics: { [F in keyof TStaticMethods]: TStaticMethods[F] } &
|
|
675
|
-
{ [name: string]: (this: TModelType, ...args: any[]) => unknown };
|
|
722
|
+
{ [name: string]: ((this: TModelType, ...args: any[]) => unknown) & SupportsMiddlewareOption };
|
|
676
723
|
|
|
677
724
|
toJSONSchema(options?: { useBsonType?: boolean }): Record<string, any>;
|
|
678
725
|
|
|
@@ -825,6 +872,7 @@ declare module 'mongoose' {
|
|
|
825
872
|
export type ReturnsNewDoc = { new: true } | { returnOriginal: false } | { returnDocument: 'after' };
|
|
826
873
|
|
|
827
874
|
export type ArrayProjectionOperators = { $slice: number | [number, number]; $elemMatch?: never } | { $elemMatch: Record<string, any>; $slice?: never };
|
|
875
|
+
export type ProjectionOperators = { $meta: string };
|
|
828
876
|
/**
|
|
829
877
|
* This Type Assigns `Element | undefined` recursively to the `T` type.
|
|
830
878
|
* if it is an array it will do this to the element of the array, if it is an object it will do this for the properties of the object.
|
|
@@ -842,14 +890,14 @@ declare module 'mongoose' {
|
|
|
842
890
|
}
|
|
843
891
|
*/
|
|
844
892
|
export type Projector<T, Element> = T extends Array<infer U>
|
|
845
|
-
? Projector<U, Element> | ArrayProjectionOperators
|
|
893
|
+
? Projector<U, Element> | ArrayProjectionOperators | ProjectionOperators
|
|
846
894
|
: T extends TreatAsPrimitives
|
|
847
|
-
? Element
|
|
895
|
+
? Element | ProjectionOperators
|
|
848
896
|
: T extends Record<string, any>
|
|
849
897
|
? {
|
|
850
|
-
[K in keyof T]?: T[K] extends Record<string, any> ? Projector<T[K], Element> | Element : Element;
|
|
898
|
+
[K in keyof T]?: T[K] extends Record<string, any> ? Projector<T[K], Element> | Element | ProjectionOperators : Element | ProjectionOperators;
|
|
851
899
|
}
|
|
852
|
-
: Element;
|
|
900
|
+
: Element | ProjectionOperators;
|
|
853
901
|
type _IDType = { _id?: boolean | number };
|
|
854
902
|
export type InclusionProjection<T> = IsItRecordAndNotAny<T> extends true
|
|
855
903
|
? Omit<Projector<WithLevel1NestedPaths<T>, boolean | number>, '_id'> & _IDType
|
|
@@ -1181,7 +1229,7 @@ declare module 'mongoose' {
|
|
|
1181
1229
|
/* for ts-mongoose */
|
|
1182
1230
|
export class mquery { }
|
|
1183
1231
|
|
|
1184
|
-
export function overwriteMiddlewareResult(val: any): Kareem.
|
|
1232
|
+
export function overwriteMiddlewareResult(val: any): Kareem.OverwriteResult;
|
|
1185
1233
|
|
|
1186
1234
|
export function skipMiddlewareFunction(val: any): Kareem.SkipWrappedFunction;
|
|
1187
1235
|
|
package/types/indexes.d.ts
CHANGED
|
@@ -94,4 +94,77 @@ declare module 'mongoose' {
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
type SearchIndexDescription = mongodb.SearchIndexDescription;
|
|
97
|
+
|
|
98
|
+
type SearchIndexStatus = 'BUILDING' | 'DELETING' | 'DOES_NOT_EXIST' | 'FAILED' | 'PENDING' | 'READY' | 'STALE';
|
|
99
|
+
|
|
100
|
+
type SearchIndexSynonymMappingStatus = 'BUILDING' | 'FAILED' | 'READY';
|
|
101
|
+
|
|
102
|
+
/** The status of one synonym mapping on one search node. */
|
|
103
|
+
interface SearchIndexSynonymMappingDetail {
|
|
104
|
+
/** The build state of the synonym mapping. */
|
|
105
|
+
status: SearchIndexSynonymMappingStatus;
|
|
106
|
+
/** Whether the synonym mapping can serve queries. */
|
|
107
|
+
queryable: boolean;
|
|
108
|
+
/** The error that made the synonym mapping fail, only returned when its status is `FAILED`. */
|
|
109
|
+
message?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The status of one index generation, active or staged, on one search node. */
|
|
113
|
+
interface SearchIndexGenerationDetail {
|
|
114
|
+
/** The build state of this index generation. */
|
|
115
|
+
status: SearchIndexStatus;
|
|
116
|
+
/** Whether this index generation is ready to serve queries. */
|
|
117
|
+
queryable: boolean;
|
|
118
|
+
/** When the definition this generation builds with was created, and its version number. */
|
|
119
|
+
definitionVersion: { version: number, createdAt: NativeDate };
|
|
120
|
+
/** The definition this generation builds with. */
|
|
121
|
+
definition: AnyObject;
|
|
122
|
+
/** The status of this generation's synonym mappings, only returned when the index defines any. */
|
|
123
|
+
synonymMappingStatus?: SearchIndexSynonymMappingStatus;
|
|
124
|
+
/** The status of each of this generation's synonym mappings, keyed by mapping name. */
|
|
125
|
+
synonymMappingStatusDetail?: Array<Record<string, SearchIndexSynonymMappingDetail>>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The status of the index on one search node (`mongot`). */
|
|
129
|
+
interface SearchIndexStatusDetail {
|
|
130
|
+
/** The hostname of the search node, in the form `<replSetName>.<server.name>.<server.id>`. */
|
|
131
|
+
hostname: string;
|
|
132
|
+
/** The build state of the index on this search node. */
|
|
133
|
+
status: SearchIndexStatus;
|
|
134
|
+
/** Whether the index is ready to serve queries on this search node. */
|
|
135
|
+
queryable: boolean;
|
|
136
|
+
/** The active index on this search node. */
|
|
137
|
+
mainIndex: SearchIndexGenerationDetail;
|
|
138
|
+
/** The index being built in the background, only returned while an existing index is being updated. */
|
|
139
|
+
stagedIndex?: SearchIndexGenerationDetail;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* A single entry of the [`$listSearchIndexes`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/)
|
|
144
|
+
* output, as returned by `Model.listSearchIndexes()`.
|
|
145
|
+
*/
|
|
146
|
+
interface SearchIndexInfo {
|
|
147
|
+
/** The index's unique identifier, a hex string rather than an ObjectId. */
|
|
148
|
+
id: string;
|
|
149
|
+
/** The name of the index. */
|
|
150
|
+
name: string;
|
|
151
|
+
/** The type of the index. Only returned for Atlas deployments. */
|
|
152
|
+
type?: 'search' | 'vectorSearch';
|
|
153
|
+
/** The build state of the index. */
|
|
154
|
+
status: SearchIndexStatus;
|
|
155
|
+
/** Whether the index is ready to serve queries. */
|
|
156
|
+
queryable: boolean;
|
|
157
|
+
/** The version number of the most recent definition. */
|
|
158
|
+
latestVersion?: number;
|
|
159
|
+
/** When the most recent definition was created, and its version number. */
|
|
160
|
+
latestDefinitionVersion?: { version: number, createdAt: NativeDate };
|
|
161
|
+
/** The most recent definition of the index. */
|
|
162
|
+
latestDefinition: AnyObject;
|
|
163
|
+
/** The status of the index on each individual search node. */
|
|
164
|
+
statusDetail?: SearchIndexStatusDetail[];
|
|
165
|
+
/** The status of the index's synonym mappings, only returned when the index defines any. */
|
|
166
|
+
synonymMappingStatus?: SearchIndexSynonymMappingStatus;
|
|
167
|
+
/** The status of each synonym mapping on each search node, keyed by mapping name. */
|
|
168
|
+
synonymMappingStatusDetail?: Array<Record<string, SearchIndexSynonymMappingDetail>>;
|
|
169
|
+
}
|
|
97
170
|
}
|
package/types/middlewares.d.ts
CHANGED
|
@@ -41,6 +41,15 @@ declare module 'mongoose' {
|
|
|
41
41
|
post?: boolean;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
interface SupportsMiddlewareOption {
|
|
45
|
+
/**
|
|
46
|
+
* Set to `true` to let callers skip this custom static's or method's middleware
|
|
47
|
+
* by passing `{ middleware: false }` as the last argument.
|
|
48
|
+
* See [skipping middleware for custom statics and methods](https://mongoosejs.com/docs/middleware.html#skip-custom-statics-and-methods).
|
|
49
|
+
*/
|
|
50
|
+
supportsMiddlewareOption?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
44
53
|
type PreMiddlewareFunction<ThisType = any> = (
|
|
45
54
|
this: ThisType,
|
|
46
55
|
opts?: Record<string, any>
|
|
@@ -60,7 +69,7 @@ declare module 'mongoose' {
|
|
|
60
69
|
this: ThisType,
|
|
61
70
|
opts: SaveOptions
|
|
62
71
|
) => void | Promise<void> | Kareem.SkipWrappedFunction;
|
|
63
|
-
type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void> | Kareem.
|
|
72
|
+
type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void> | Kareem.OverwriteResult;
|
|
64
73
|
type ErrorHandlingMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: CallbackWithoutResultAndOptionalError) => void;
|
|
65
|
-
type ErrorHandlingMiddlewareWithOption<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType | null, next: CallbackWithoutResultAndOptionalError) => void | Promise<void> | Kareem.
|
|
74
|
+
type ErrorHandlingMiddlewareWithOption<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType | null, next: CallbackWithoutResultAndOptionalError) => void | Promise<void> | Kareem.OverwriteResult;
|
|
66
75
|
}
|
package/types/models.d.ts
CHANGED
|
@@ -445,6 +445,18 @@ declare module 'mongoose' {
|
|
|
445
445
|
* equivalent to `findOne({ _id: id })`. If you want to query by a document's
|
|
446
446
|
* `_id`, use `findById()` instead of `findOne()`.
|
|
447
447
|
*/
|
|
448
|
+
findById<const Projection extends ProjectionType<TRawDocType>>(
|
|
449
|
+
id: any,
|
|
450
|
+
projection: Projection,
|
|
451
|
+
options: QueryOptions<TRawDocType> & { lean: true }
|
|
452
|
+
): QueryWithHelpers<
|
|
453
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
454
|
+
THydratedDocumentType,
|
|
455
|
+
TQueryHelpers,
|
|
456
|
+
TLeanResultType,
|
|
457
|
+
'findOne',
|
|
458
|
+
TInstanceMethods & TVirtuals
|
|
459
|
+
>;
|
|
448
460
|
findById<ResultDoc = THydratedDocumentType>(
|
|
449
461
|
id: any,
|
|
450
462
|
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
@@ -483,6 +495,54 @@ declare module 'mongoose' {
|
|
|
483
495
|
>;
|
|
484
496
|
|
|
485
497
|
/** Finds one document. */
|
|
498
|
+
findOne<const Projection extends ProjectionType<TRawDocType>>(
|
|
499
|
+
filter: QueryFilter<TRawDocType>,
|
|
500
|
+
projection: Projection,
|
|
501
|
+
options?: QueryOptions<TRawDocType> & { lean?: false } & mongodb.Abortable
|
|
502
|
+
): QueryWithHelpers<
|
|
503
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
504
|
+
THydratedDocumentType,
|
|
505
|
+
TQueryHelpers,
|
|
506
|
+
TLeanResultType,
|
|
507
|
+
'findOne',
|
|
508
|
+
TInstanceMethods & TVirtuals
|
|
509
|
+
>;
|
|
510
|
+
findOne<const Projection extends ProjectionType<TRawDocType>>(
|
|
511
|
+
filter: QueryFilter<TRawDocType>,
|
|
512
|
+
projection: undefined | null,
|
|
513
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false } & mongodb.Abortable
|
|
514
|
+
): QueryWithHelpers<
|
|
515
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
516
|
+
THydratedDocumentType,
|
|
517
|
+
TQueryHelpers,
|
|
518
|
+
TLeanResultType,
|
|
519
|
+
'findOne',
|
|
520
|
+
TInstanceMethods & TVirtuals
|
|
521
|
+
>;
|
|
522
|
+
findOne<const Projection extends ProjectionType<TRawDocType>>(
|
|
523
|
+
filter: QueryFilter<TRawDocType>,
|
|
524
|
+
projection: Projection,
|
|
525
|
+
options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
|
|
526
|
+
): QueryWithHelpers<
|
|
527
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
528
|
+
THydratedDocumentType,
|
|
529
|
+
TQueryHelpers,
|
|
530
|
+
TLeanResultType,
|
|
531
|
+
'findOne',
|
|
532
|
+
TInstanceMethods & TVirtuals
|
|
533
|
+
>;
|
|
534
|
+
findOne<const Projection extends ProjectionType<TRawDocType>>(
|
|
535
|
+
filter: QueryFilter<TRawDocType>,
|
|
536
|
+
projection: undefined | null,
|
|
537
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true } & mongodb.Abortable
|
|
538
|
+
): QueryWithHelpers<
|
|
539
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
540
|
+
THydratedDocumentType,
|
|
541
|
+
TQueryHelpers,
|
|
542
|
+
TLeanResultType,
|
|
543
|
+
'findOne',
|
|
544
|
+
TInstanceMethods & TVirtuals
|
|
545
|
+
>;
|
|
486
546
|
findOne<ResultDoc = THydratedDocumentType>(
|
|
487
547
|
filter: QueryFilter<TRawDocType>,
|
|
488
548
|
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
@@ -658,7 +718,7 @@ declare module 'mongoose' {
|
|
|
658
718
|
* List all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) on this model's collection.
|
|
659
719
|
* This function only works when connected to MongoDB Atlas.
|
|
660
720
|
*/
|
|
661
|
-
listSearchIndexes(options?: mongodb.ListSearchIndexesOptions): Promise<Array<
|
|
721
|
+
listSearchIndexes(options?: mongodb.ListSearchIndexesOptions): Promise<Array<SearchIndexInfo>>;
|
|
662
722
|
|
|
663
723
|
/** The name of the model */
|
|
664
724
|
modelName: string;
|
|
@@ -780,6 +840,54 @@ declare module 'mongoose' {
|
|
|
780
840
|
>;
|
|
781
841
|
|
|
782
842
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
843
|
+
find<const Projection extends ProjectionType<TRawDocType>>(
|
|
844
|
+
filter: QueryFilter<TRawDocType>,
|
|
845
|
+
projection: Projection,
|
|
846
|
+
options?: QueryOptions<TRawDocType> & { lean?: false } & mongodb.Abortable
|
|
847
|
+
): QueryWithHelpers<
|
|
848
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>[],
|
|
849
|
+
THydratedDocumentType,
|
|
850
|
+
TQueryHelpers,
|
|
851
|
+
TLeanResultType,
|
|
852
|
+
'find',
|
|
853
|
+
TInstanceMethods & TVirtuals
|
|
854
|
+
>;
|
|
855
|
+
find<const Projection extends ProjectionType<TRawDocType>>(
|
|
856
|
+
filter: QueryFilter<TRawDocType>,
|
|
857
|
+
projection: undefined | null,
|
|
858
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false } & mongodb.Abortable
|
|
859
|
+
): QueryWithHelpers<
|
|
860
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>[],
|
|
861
|
+
THydratedDocumentType,
|
|
862
|
+
TQueryHelpers,
|
|
863
|
+
TLeanResultType,
|
|
864
|
+
'find',
|
|
865
|
+
TInstanceMethods & TVirtuals
|
|
866
|
+
>;
|
|
867
|
+
find<const Projection extends ProjectionType<TRawDocType>>(
|
|
868
|
+
filter: QueryFilter<TRawDocType>,
|
|
869
|
+
projection: Projection,
|
|
870
|
+
options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
|
|
871
|
+
): QueryWithHelpers<
|
|
872
|
+
ApplyProjection<TRawDocType, Projection>[],
|
|
873
|
+
THydratedDocumentType,
|
|
874
|
+
TQueryHelpers,
|
|
875
|
+
TLeanResultType,
|
|
876
|
+
'find',
|
|
877
|
+
TInstanceMethods & TVirtuals
|
|
878
|
+
>;
|
|
879
|
+
find<const Projection extends ProjectionType<TRawDocType>>(
|
|
880
|
+
filter: QueryFilter<TRawDocType>,
|
|
881
|
+
projection: undefined | null,
|
|
882
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true } & mongodb.Abortable
|
|
883
|
+
): QueryWithHelpers<
|
|
884
|
+
ApplyProjection<TRawDocType, Projection>[],
|
|
885
|
+
THydratedDocumentType,
|
|
886
|
+
TQueryHelpers,
|
|
887
|
+
TLeanResultType,
|
|
888
|
+
'find',
|
|
889
|
+
TInstanceMethods & TVirtuals
|
|
890
|
+
>;
|
|
783
891
|
find<ResultDoc = THydratedDocumentType>(
|
|
784
892
|
filter: QueryFilter<TRawDocType>,
|
|
785
893
|
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
@@ -841,7 +949,51 @@ declare module 'mongoose' {
|
|
|
841
949
|
TInstanceMethods & TVirtuals
|
|
842
950
|
>;
|
|
843
951
|
|
|
952
|
+
/** Finds documents and counts the number of documents matching `filter`. */
|
|
953
|
+
findAndCount<const Projection extends ProjectionType<TRawDocType>>(
|
|
954
|
+
filter: QueryFilter<TRawDocType>,
|
|
955
|
+
projection: Projection,
|
|
956
|
+
options: QueryOptions<TRawDocType> & { sort: any; limit: number; lean: true } & mongodb.Abortable
|
|
957
|
+
): Promise<[ApplyProjection<TRawDocType, Projection>[], number]>;
|
|
958
|
+
findAndCount<ResultDoc = THydratedDocumentType>(
|
|
959
|
+
filter: QueryFilter<TRawDocType>,
|
|
960
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
961
|
+
options: QueryOptions<TRawDocType> & { sort: any; limit: number; lean: true } & mongodb.Abortable
|
|
962
|
+
): Promise<[GetLeanResultType<TRawDocType, TRawDocType[], 'find'>, number]>;
|
|
963
|
+
findAndCount<ResultDoc = THydratedDocumentType>(
|
|
964
|
+
filter: QueryFilter<TRawDocType>,
|
|
965
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
966
|
+
options: QueryOptions<TRawDocType> & { sort: any; limit: number; lean: false } & mongodb.Abortable
|
|
967
|
+
): Promise<[ResultDoc[], number]>;
|
|
968
|
+
findAndCount<ResultDoc = THydratedDocumentType>(
|
|
969
|
+
filter: QueryFilter<TRawDocType>,
|
|
970
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
971
|
+
options: QueryOptions<TRawDocType> & { sort: any; limit: number } & mongodb.Abortable
|
|
972
|
+
): Promise<[HasLeanOption<TSchema> extends true ? TLeanResultType[] : ResultDoc[], number]>;
|
|
973
|
+
|
|
844
974
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
975
|
+
findByIdAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
976
|
+
id: mongodb.ObjectId | any,
|
|
977
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
978
|
+
): QueryWithHelpers<
|
|
979
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
980
|
+
THydratedDocumentType,
|
|
981
|
+
TQueryHelpers,
|
|
982
|
+
TLeanResultType,
|
|
983
|
+
'findOneAndDelete',
|
|
984
|
+
TInstanceMethods & TVirtuals
|
|
985
|
+
>;
|
|
986
|
+
findByIdAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
987
|
+
id: mongodb.ObjectId | any,
|
|
988
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
989
|
+
): QueryWithHelpers<
|
|
990
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
991
|
+
THydratedDocumentType,
|
|
992
|
+
TQueryHelpers,
|
|
993
|
+
TLeanResultType,
|
|
994
|
+
'findOneAndDelete',
|
|
995
|
+
TInstanceMethods & TVirtuals
|
|
996
|
+
>;
|
|
845
997
|
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
846
998
|
id: mongodb.ObjectId | any,
|
|
847
999
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true, lean: true }
|
|
@@ -900,6 +1052,30 @@ declare module 'mongoose' {
|
|
|
900
1052
|
|
|
901
1053
|
|
|
902
1054
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
1055
|
+
findByIdAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1056
|
+
id: mongodb.ObjectId | any,
|
|
1057
|
+
update: UpdateQuery<TRawDocType>,
|
|
1058
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
1059
|
+
): QueryWithHelpers<
|
|
1060
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
1061
|
+
THydratedDocumentType,
|
|
1062
|
+
TQueryHelpers,
|
|
1063
|
+
TLeanResultType,
|
|
1064
|
+
'findOneAndUpdate',
|
|
1065
|
+
TInstanceMethods & TVirtuals
|
|
1066
|
+
>;
|
|
1067
|
+
findByIdAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1068
|
+
id: mongodb.ObjectId | any,
|
|
1069
|
+
update: UpdateQuery<TRawDocType>,
|
|
1070
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
1071
|
+
): QueryWithHelpers<
|
|
1072
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
1073
|
+
THydratedDocumentType,
|
|
1074
|
+
TQueryHelpers,
|
|
1075
|
+
TLeanResultType,
|
|
1076
|
+
'findOneAndUpdate',
|
|
1077
|
+
TInstanceMethods & TVirtuals
|
|
1078
|
+
>;
|
|
903
1079
|
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
904
1080
|
filter: QueryFilter<TRawDocType>,
|
|
905
1081
|
update: UpdateQuery<TRawDocType>,
|
|
@@ -986,6 +1162,50 @@ declare module 'mongoose' {
|
|
|
986
1162
|
>;
|
|
987
1163
|
|
|
988
1164
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
1165
|
+
findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
1166
|
+
filter: QueryFilter<TRawDocType>,
|
|
1167
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata?: false }
|
|
1168
|
+
): QueryWithHelpers<
|
|
1169
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
1170
|
+
THydratedDocumentType,
|
|
1171
|
+
TQueryHelpers,
|
|
1172
|
+
TLeanResultType,
|
|
1173
|
+
'findOneAndDelete',
|
|
1174
|
+
TInstanceMethods & TVirtuals
|
|
1175
|
+
>;
|
|
1176
|
+
findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
1177
|
+
filter: QueryFilter<TRawDocType>,
|
|
1178
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata: true }
|
|
1179
|
+
): QueryWithHelpers<
|
|
1180
|
+
ModifyResult<ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>>,
|
|
1181
|
+
THydratedDocumentType,
|
|
1182
|
+
TQueryHelpers,
|
|
1183
|
+
TLeanResultType,
|
|
1184
|
+
'findOneAndDelete',
|
|
1185
|
+
TInstanceMethods & TVirtuals
|
|
1186
|
+
>;
|
|
1187
|
+
findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
1188
|
+
filter: QueryFilter<TRawDocType>,
|
|
1189
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
1190
|
+
): QueryWithHelpers<
|
|
1191
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
1192
|
+
THydratedDocumentType,
|
|
1193
|
+
TQueryHelpers,
|
|
1194
|
+
TLeanResultType,
|
|
1195
|
+
'findOneAndDelete',
|
|
1196
|
+
TInstanceMethods & TVirtuals
|
|
1197
|
+
>;
|
|
1198
|
+
findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
|
|
1199
|
+
filter: QueryFilter<TRawDocType>,
|
|
1200
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
1201
|
+
): QueryWithHelpers<
|
|
1202
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
1203
|
+
THydratedDocumentType,
|
|
1204
|
+
TQueryHelpers,
|
|
1205
|
+
TLeanResultType,
|
|
1206
|
+
'findOneAndDelete',
|
|
1207
|
+
TInstanceMethods & TVirtuals
|
|
1208
|
+
>;
|
|
989
1209
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
990
1210
|
filter: QueryFilter<TRawDocType>,
|
|
991
1211
|
options: QueryOptions<TRawDocType> & { lean: true }
|
|
@@ -1076,6 +1296,54 @@ declare module 'mongoose' {
|
|
|
1076
1296
|
>;
|
|
1077
1297
|
|
|
1078
1298
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
1299
|
+
findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
|
|
1300
|
+
filter: QueryFilter<TRawDocType>,
|
|
1301
|
+
replacement: TRawDocType | AnyObject,
|
|
1302
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata?: false }
|
|
1303
|
+
): QueryWithHelpers<
|
|
1304
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
1305
|
+
THydratedDocumentType,
|
|
1306
|
+
TQueryHelpers,
|
|
1307
|
+
TLeanResultType,
|
|
1308
|
+
'findOneAndReplace',
|
|
1309
|
+
TInstanceMethods & TVirtuals
|
|
1310
|
+
>;
|
|
1311
|
+
findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
|
|
1312
|
+
filter: QueryFilter<TRawDocType>,
|
|
1313
|
+
replacement: TRawDocType | AnyObject,
|
|
1314
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata: true }
|
|
1315
|
+
): QueryWithHelpers<
|
|
1316
|
+
ModifyResult<ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>>,
|
|
1317
|
+
THydratedDocumentType,
|
|
1318
|
+
TQueryHelpers,
|
|
1319
|
+
TLeanResultType,
|
|
1320
|
+
'findOneAndReplace',
|
|
1321
|
+
TInstanceMethods & TVirtuals
|
|
1322
|
+
>;
|
|
1323
|
+
findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
|
|
1324
|
+
filter: QueryFilter<TRawDocType>,
|
|
1325
|
+
replacement: TRawDocType | AnyObject,
|
|
1326
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
1327
|
+
): QueryWithHelpers<
|
|
1328
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
1329
|
+
THydratedDocumentType,
|
|
1330
|
+
TQueryHelpers,
|
|
1331
|
+
TLeanResultType,
|
|
1332
|
+
'findOneAndReplace',
|
|
1333
|
+
TInstanceMethods & TVirtuals
|
|
1334
|
+
>;
|
|
1335
|
+
findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
|
|
1336
|
+
filter: QueryFilter<TRawDocType>,
|
|
1337
|
+
replacement: TRawDocType | AnyObject,
|
|
1338
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
1339
|
+
): QueryWithHelpers<
|
|
1340
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
1341
|
+
THydratedDocumentType,
|
|
1342
|
+
TQueryHelpers,
|
|
1343
|
+
TLeanResultType,
|
|
1344
|
+
'findOneAndReplace',
|
|
1345
|
+
TInstanceMethods & TVirtuals
|
|
1346
|
+
>;
|
|
1079
1347
|
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
1080
1348
|
filter: QueryFilter<TRawDocType>,
|
|
1081
1349
|
replacement: TRawDocType | AnyObject,
|
|
@@ -1198,6 +1466,54 @@ declare module 'mongoose' {
|
|
|
1198
1466
|
>;
|
|
1199
1467
|
|
|
1200
1468
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
1469
|
+
findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1470
|
+
filter: QueryFilter<TRawDocType>,
|
|
1471
|
+
update: UpdateQuery<TRawDocType>,
|
|
1472
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata?: false }
|
|
1473
|
+
): QueryWithHelpers<
|
|
1474
|
+
ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals> | null,
|
|
1475
|
+
THydratedDocumentType,
|
|
1476
|
+
TQueryHelpers,
|
|
1477
|
+
TLeanResultType,
|
|
1478
|
+
'findOneAndUpdate',
|
|
1479
|
+
TInstanceMethods & TVirtuals
|
|
1480
|
+
>;
|
|
1481
|
+
findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1482
|
+
filter: QueryFilter<TRawDocType>,
|
|
1483
|
+
update: UpdateQuery<TRawDocType>,
|
|
1484
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean?: false; includeResultMetadata: true }
|
|
1485
|
+
): QueryWithHelpers<
|
|
1486
|
+
ModifyResult<ProjectedHydratedDocument<TRawDocType, Projection, TInstanceMethods, TQueryHelpers, TVirtuals>>,
|
|
1487
|
+
THydratedDocumentType,
|
|
1488
|
+
TQueryHelpers,
|
|
1489
|
+
TLeanResultType,
|
|
1490
|
+
'findOneAndUpdate',
|
|
1491
|
+
TInstanceMethods & TVirtuals
|
|
1492
|
+
>;
|
|
1493
|
+
findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1494
|
+
filter: QueryFilter<TRawDocType>,
|
|
1495
|
+
update: UpdateQuery<TRawDocType>,
|
|
1496
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata?: false }
|
|
1497
|
+
): QueryWithHelpers<
|
|
1498
|
+
ApplyProjection<TRawDocType, Projection> | null,
|
|
1499
|
+
THydratedDocumentType,
|
|
1500
|
+
TQueryHelpers,
|
|
1501
|
+
TLeanResultType,
|
|
1502
|
+
'findOneAndUpdate',
|
|
1503
|
+
TInstanceMethods & TVirtuals
|
|
1504
|
+
>;
|
|
1505
|
+
findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
|
|
1506
|
+
filter: QueryFilter<TRawDocType>,
|
|
1507
|
+
update: UpdateQuery<TRawDocType>,
|
|
1508
|
+
options: QueryOptions<TRawDocType> & { projection: Projection; lean: true; includeResultMetadata: true }
|
|
1509
|
+
): QueryWithHelpers<
|
|
1510
|
+
ModifyResult<ApplyProjection<TRawDocType, Projection>>,
|
|
1511
|
+
THydratedDocumentType,
|
|
1512
|
+
TQueryHelpers,
|
|
1513
|
+
TLeanResultType,
|
|
1514
|
+
'findOneAndUpdate',
|
|
1515
|
+
TInstanceMethods & TVirtuals
|
|
1516
|
+
>;
|
|
1201
1517
|
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1202
1518
|
filter: QueryFilter<TRawDocType>,
|
|
1203
1519
|
update: UpdateQuery<TRawDocType>,
|