mongoose 8.18.3 → 8.19.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/dist/browser.umd.js +1 -1
- package/lib/document.js +6 -2
- package/lib/helpers/schema/getPath.js +4 -1
- package/lib/model.js +16 -5
- package/lib/schema/documentArray.js +1 -1
- package/lib/schema/map.js +2 -2
- package/lib/schema/subdocument.js +1 -1
- package/lib/schemaType.js +1 -0
- package/package.json +5 -3
- package/types/index.d.ts +17 -8
- package/types/inferrawdoctype.d.ts +76 -95
- package/types/inferschematype.d.ts +214 -213
- package/types/models.d.ts +194 -26
- package/types/query.d.ts +76 -31
- package/types/schemaoptions.d.ts +3 -0
- package/types/schematypes.d.ts +86 -33
- package/types/utility.d.ts +108 -81
package/types/models.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ declare module 'mongoose' {
|
|
|
58
58
|
interface HydrateOptions {
|
|
59
59
|
setters?: boolean;
|
|
60
60
|
hydratedPopulatedDocs?: boolean;
|
|
61
|
+
virtuals?: boolean;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
interface InsertManyOptions extends
|
|
@@ -260,6 +261,12 @@ declare module 'mongoose' {
|
|
|
260
261
|
hint?: mongodb.Hint;
|
|
261
262
|
}
|
|
262
263
|
|
|
264
|
+
type HasLeanOption<TSchema> = 'lean' extends keyof ObtainSchemaGeneric<TSchema, 'TSchemaOptions'> ?
|
|
265
|
+
ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>['lean'] extends Record<string, any> ?
|
|
266
|
+
true :
|
|
267
|
+
ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>['lean'] :
|
|
268
|
+
false;
|
|
269
|
+
|
|
263
270
|
/**
|
|
264
271
|
* Models are fancy constructors compiled from `Schema` definitions.
|
|
265
272
|
* An instance of a model is called a document.
|
|
@@ -480,11 +487,25 @@ declare module 'mongoose' {
|
|
|
480
487
|
id: any,
|
|
481
488
|
projection?: ProjectionType<TRawDocType> | null,
|
|
482
489
|
options?: QueryOptions<TRawDocType> | null
|
|
483
|
-
): QueryWithHelpers<
|
|
490
|
+
): QueryWithHelpers<
|
|
491
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
492
|
+
ResultDoc,
|
|
493
|
+
TQueryHelpers,
|
|
494
|
+
TRawDocType,
|
|
495
|
+
'findOne',
|
|
496
|
+
TInstanceMethods & TVirtuals
|
|
497
|
+
>;
|
|
484
498
|
findById<ResultDoc = THydratedDocumentType>(
|
|
485
499
|
id: any,
|
|
486
500
|
projection?: ProjectionType<TRawDocType> | null
|
|
487
|
-
): QueryWithHelpers<
|
|
501
|
+
): QueryWithHelpers<
|
|
502
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
503
|
+
ResultDoc,
|
|
504
|
+
TQueryHelpers,
|
|
505
|
+
TRawDocType,
|
|
506
|
+
'findOne',
|
|
507
|
+
TInstanceMethods & TVirtuals
|
|
508
|
+
>;
|
|
488
509
|
|
|
489
510
|
/** Finds one document. */
|
|
490
511
|
findOne<ResultDoc = THydratedDocumentType>(
|
|
@@ -503,14 +524,35 @@ declare module 'mongoose' {
|
|
|
503
524
|
filter?: RootFilterQuery<TRawDocType>,
|
|
504
525
|
projection?: ProjectionType<TRawDocType> | null,
|
|
505
526
|
options?: QueryOptions<TRawDocType> & mongodb.Abortable | null
|
|
506
|
-
): QueryWithHelpers<
|
|
527
|
+
): QueryWithHelpers<
|
|
528
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
529
|
+
ResultDoc,
|
|
530
|
+
TQueryHelpers,
|
|
531
|
+
TRawDocType,
|
|
532
|
+
'findOne',
|
|
533
|
+
TInstanceMethods & TVirtuals
|
|
534
|
+
>;
|
|
507
535
|
findOne<ResultDoc = THydratedDocumentType>(
|
|
508
536
|
filter?: RootFilterQuery<TRawDocType>,
|
|
509
537
|
projection?: ProjectionType<TRawDocType> | null
|
|
510
|
-
): QueryWithHelpers<
|
|
538
|
+
): QueryWithHelpers<
|
|
539
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
540
|
+
ResultDoc,
|
|
541
|
+
TQueryHelpers,
|
|
542
|
+
TRawDocType,
|
|
543
|
+
'findOne',
|
|
544
|
+
TInstanceMethods & TVirtuals
|
|
545
|
+
>;
|
|
511
546
|
findOne<ResultDoc = THydratedDocumentType>(
|
|
512
547
|
filter?: RootFilterQuery<TRawDocType>
|
|
513
|
-
): QueryWithHelpers<
|
|
548
|
+
): QueryWithHelpers<
|
|
549
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
550
|
+
ResultDoc,
|
|
551
|
+
TQueryHelpers,
|
|
552
|
+
TRawDocType,
|
|
553
|
+
'findOne',
|
|
554
|
+
TInstanceMethods & TVirtuals
|
|
555
|
+
>;
|
|
514
556
|
|
|
515
557
|
/**
|
|
516
558
|
* Shortcut for creating a new Document from existing raw data, pre-saved in the DB.
|
|
@@ -734,16 +776,44 @@ declare module 'mongoose' {
|
|
|
734
776
|
filter: RootFilterQuery<TRawDocType>,
|
|
735
777
|
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
736
778
|
options?: QueryOptions<TRawDocType> & mongodb.Abortable | null | undefined
|
|
737
|
-
): QueryWithHelpers<
|
|
779
|
+
): QueryWithHelpers<
|
|
780
|
+
HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[],
|
|
781
|
+
ResultDoc,
|
|
782
|
+
TQueryHelpers,
|
|
783
|
+
TRawDocType,
|
|
784
|
+
'find',
|
|
785
|
+
TInstanceMethods & TVirtuals
|
|
786
|
+
>;
|
|
738
787
|
find<ResultDoc = THydratedDocumentType>(
|
|
739
788
|
filter: RootFilterQuery<TRawDocType>,
|
|
740
789
|
projection?: ProjectionType<TRawDocType> | null | undefined
|
|
741
|
-
): QueryWithHelpers<
|
|
790
|
+
): QueryWithHelpers<
|
|
791
|
+
HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[],
|
|
792
|
+
ResultDoc,
|
|
793
|
+
TQueryHelpers,
|
|
794
|
+
TRawDocType,
|
|
795
|
+
'find',
|
|
796
|
+
TInstanceMethods & TVirtuals
|
|
797
|
+
>;
|
|
742
798
|
find<ResultDoc = THydratedDocumentType>(
|
|
743
799
|
filter: RootFilterQuery<TRawDocType>
|
|
744
|
-
): QueryWithHelpers<
|
|
800
|
+
): QueryWithHelpers<
|
|
801
|
+
HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[],
|
|
802
|
+
ResultDoc,
|
|
803
|
+
TQueryHelpers,
|
|
804
|
+
TRawDocType,
|
|
805
|
+
'find',
|
|
806
|
+
TInstanceMethods & TVirtuals
|
|
807
|
+
>;
|
|
745
808
|
find<ResultDoc = THydratedDocumentType>(
|
|
746
|
-
): QueryWithHelpers<
|
|
809
|
+
): QueryWithHelpers<
|
|
810
|
+
HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[],
|
|
811
|
+
ResultDoc,
|
|
812
|
+
TQueryHelpers,
|
|
813
|
+
TRawDocType,
|
|
814
|
+
'find',
|
|
815
|
+
TInstanceMethods & TVirtuals
|
|
816
|
+
>;
|
|
747
817
|
|
|
748
818
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
749
819
|
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
@@ -760,11 +830,25 @@ declare module 'mongoose' {
|
|
|
760
830
|
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
761
831
|
id: mongodb.ObjectId | any,
|
|
762
832
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
763
|
-
): QueryWithHelpers<
|
|
833
|
+
): QueryWithHelpers<
|
|
834
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TRawDocType> : ModifyResult<ResultDoc>,
|
|
835
|
+
ResultDoc,
|
|
836
|
+
TQueryHelpers,
|
|
837
|
+
TRawDocType,
|
|
838
|
+
'findOneAndDelete',
|
|
839
|
+
TInstanceMethods & TVirtuals
|
|
840
|
+
>;
|
|
764
841
|
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
765
842
|
id?: mongodb.ObjectId | any,
|
|
766
843
|
options?: QueryOptions<TRawDocType> | null
|
|
767
|
-
): QueryWithHelpers<
|
|
844
|
+
): QueryWithHelpers<
|
|
845
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
846
|
+
ResultDoc,
|
|
847
|
+
TQueryHelpers,
|
|
848
|
+
TRawDocType,
|
|
849
|
+
'findOneAndDelete',
|
|
850
|
+
TInstanceMethods & TVirtuals
|
|
851
|
+
>;
|
|
768
852
|
|
|
769
853
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
770
854
|
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
@@ -795,21 +879,49 @@ declare module 'mongoose' {
|
|
|
795
879
|
id: mongodb.ObjectId | any,
|
|
796
880
|
update: UpdateQuery<TRawDocType>,
|
|
797
881
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
798
|
-
): QueryWithHelpers<
|
|
882
|
+
): QueryWithHelpers<
|
|
883
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TRawDocType> : ModifyResult<ResultDoc>,
|
|
884
|
+
ResultDoc,
|
|
885
|
+
TQueryHelpers,
|
|
886
|
+
TRawDocType,
|
|
887
|
+
'findOneAndUpdate',
|
|
888
|
+
TInstanceMethods & TVirtuals
|
|
889
|
+
>;
|
|
799
890
|
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
800
891
|
id: mongodb.ObjectId | any,
|
|
801
892
|
update: UpdateQuery<TRawDocType>,
|
|
802
893
|
options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
|
|
803
|
-
): QueryWithHelpers<
|
|
894
|
+
): QueryWithHelpers<
|
|
895
|
+
HasLeanOption<TSchema> extends true ? TRawDocType : ResultDoc,
|
|
896
|
+
ResultDoc,
|
|
897
|
+
TQueryHelpers,
|
|
898
|
+
TRawDocType,
|
|
899
|
+
'findOneAndUpdate',
|
|
900
|
+
TInstanceMethods & TVirtuals
|
|
901
|
+
>;
|
|
804
902
|
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
805
903
|
id?: mongodb.ObjectId | any,
|
|
806
904
|
update?: UpdateQuery<TRawDocType>,
|
|
807
905
|
options?: QueryOptions<TRawDocType> | null
|
|
808
|
-
): QueryWithHelpers<
|
|
906
|
+
): QueryWithHelpers<
|
|
907
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
908
|
+
ResultDoc,
|
|
909
|
+
TQueryHelpers,
|
|
910
|
+
TRawDocType,
|
|
911
|
+
'findOneAndUpdate',
|
|
912
|
+
TInstanceMethods & TVirtuals
|
|
913
|
+
>;
|
|
809
914
|
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
810
915
|
id: mongodb.ObjectId | any,
|
|
811
916
|
update: UpdateQuery<TRawDocType>
|
|
812
|
-
): QueryWithHelpers<
|
|
917
|
+
): QueryWithHelpers<
|
|
918
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
919
|
+
ResultDoc,
|
|
920
|
+
TQueryHelpers,
|
|
921
|
+
TRawDocType,
|
|
922
|
+
'findOneAndUpdate',
|
|
923
|
+
TInstanceMethods & TVirtuals
|
|
924
|
+
>;
|
|
813
925
|
|
|
814
926
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
815
927
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
@@ -826,11 +938,25 @@ declare module 'mongoose' {
|
|
|
826
938
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
827
939
|
filter: RootFilterQuery<TRawDocType>,
|
|
828
940
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
829
|
-
): QueryWithHelpers<
|
|
941
|
+
): QueryWithHelpers<
|
|
942
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TRawDocType> : ModifyResult<ResultDoc>,
|
|
943
|
+
ResultDoc,
|
|
944
|
+
TQueryHelpers,
|
|
945
|
+
TRawDocType,
|
|
946
|
+
'findOneAndDelete',
|
|
947
|
+
TInstanceMethods & TVirtuals
|
|
948
|
+
>;
|
|
830
949
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
831
950
|
filter?: RootFilterQuery<TRawDocType> | null,
|
|
832
951
|
options?: QueryOptions<TRawDocType> | null
|
|
833
|
-
): QueryWithHelpers<
|
|
952
|
+
): QueryWithHelpers<
|
|
953
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
954
|
+
ResultDoc,
|
|
955
|
+
TQueryHelpers,
|
|
956
|
+
TRawDocType,
|
|
957
|
+
'findOneAndDelete',
|
|
958
|
+
TInstanceMethods & TVirtuals
|
|
959
|
+
>;
|
|
834
960
|
|
|
835
961
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
836
962
|
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
@@ -849,17 +975,38 @@ declare module 'mongoose' {
|
|
|
849
975
|
filter: RootFilterQuery<TRawDocType>,
|
|
850
976
|
replacement: TRawDocType | AnyObject,
|
|
851
977
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
852
|
-
): QueryWithHelpers<
|
|
978
|
+
): QueryWithHelpers<
|
|
979
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TRawDocType> : ModifyResult<ResultDoc>,
|
|
980
|
+
ResultDoc,
|
|
981
|
+
TQueryHelpers,
|
|
982
|
+
TRawDocType,
|
|
983
|
+
'findOneAndReplace',
|
|
984
|
+
TInstanceMethods & TVirtuals
|
|
985
|
+
>;
|
|
853
986
|
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
854
987
|
filter: RootFilterQuery<TRawDocType>,
|
|
855
988
|
replacement: TRawDocType | AnyObject,
|
|
856
989
|
options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
|
|
857
|
-
): QueryWithHelpers<
|
|
990
|
+
): QueryWithHelpers<
|
|
991
|
+
HasLeanOption<TSchema> extends true ? TRawDocType : ResultDoc,
|
|
992
|
+
ResultDoc,
|
|
993
|
+
TQueryHelpers,
|
|
994
|
+
TRawDocType,
|
|
995
|
+
'findOneAndReplace',
|
|
996
|
+
TInstanceMethods & TVirtuals
|
|
997
|
+
>;
|
|
858
998
|
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
859
999
|
filter?: RootFilterQuery<TRawDocType>,
|
|
860
1000
|
replacement?: TRawDocType | AnyObject,
|
|
861
1001
|
options?: QueryOptions<TRawDocType> | null
|
|
862
|
-
): QueryWithHelpers<
|
|
1002
|
+
): QueryWithHelpers<
|
|
1003
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
1004
|
+
ResultDoc,
|
|
1005
|
+
TQueryHelpers,
|
|
1006
|
+
TRawDocType,
|
|
1007
|
+
'findOneAndReplace',
|
|
1008
|
+
TInstanceMethods & TVirtuals
|
|
1009
|
+
>;
|
|
863
1010
|
|
|
864
1011
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
865
1012
|
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
@@ -890,17 +1037,38 @@ declare module 'mongoose' {
|
|
|
890
1037
|
filter: RootFilterQuery<TRawDocType>,
|
|
891
1038
|
update: UpdateQuery<TRawDocType>,
|
|
892
1039
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
893
|
-
): QueryWithHelpers<
|
|
1040
|
+
): QueryWithHelpers<
|
|
1041
|
+
HasLeanOption<TSchema> extends true ? ModifyResult<TRawDocType> : ModifyResult<ResultDoc>,
|
|
1042
|
+
ResultDoc,
|
|
1043
|
+
TQueryHelpers,
|
|
1044
|
+
TRawDocType,
|
|
1045
|
+
'findOneAndUpdate',
|
|
1046
|
+
TInstanceMethods & TVirtuals
|
|
1047
|
+
>;
|
|
894
1048
|
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
895
1049
|
filter: RootFilterQuery<TRawDocType>,
|
|
896
1050
|
update: UpdateQuery<TRawDocType>,
|
|
897
1051
|
options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
|
|
898
|
-
): QueryWithHelpers<
|
|
1052
|
+
): QueryWithHelpers<
|
|
1053
|
+
HasLeanOption<TSchema> extends true ? TRawDocType : ResultDoc,
|
|
1054
|
+
ResultDoc,
|
|
1055
|
+
TQueryHelpers,
|
|
1056
|
+
TRawDocType,
|
|
1057
|
+
'findOneAndUpdate',
|
|
1058
|
+
TInstanceMethods & TVirtuals
|
|
1059
|
+
>;
|
|
899
1060
|
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
900
1061
|
filter?: RootFilterQuery<TRawDocType>,
|
|
901
1062
|
update?: UpdateQuery<TRawDocType>,
|
|
902
1063
|
options?: QueryOptions<TRawDocType> | null
|
|
903
|
-
): QueryWithHelpers<
|
|
1064
|
+
): QueryWithHelpers<
|
|
1065
|
+
HasLeanOption<TSchema> extends true ? TRawDocType | null : ResultDoc | null,
|
|
1066
|
+
ResultDoc,
|
|
1067
|
+
TQueryHelpers,
|
|
1068
|
+
TRawDocType,
|
|
1069
|
+
'findOneAndUpdate',
|
|
1070
|
+
TInstanceMethods & TVirtuals
|
|
1071
|
+
>;
|
|
904
1072
|
|
|
905
1073
|
/** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
|
|
906
1074
|
replaceOne<ResultDoc = THydratedDocumentType>(
|
|
@@ -936,9 +1104,9 @@ declare module 'mongoose' {
|
|
|
936
1104
|
where<ResultDoc = THydratedDocumentType>(
|
|
937
1105
|
path: string,
|
|
938
1106
|
val?: any
|
|
939
|
-
): QueryWithHelpers<
|
|
1107
|
+
): QueryWithHelpers<HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[], ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>;
|
|
940
1108
|
where<ResultDoc = THydratedDocumentType>(obj: object): QueryWithHelpers<
|
|
941
|
-
|
|
1109
|
+
HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[],
|
|
942
1110
|
ResultDoc,
|
|
943
1111
|
TQueryHelpers,
|
|
944
1112
|
TRawDocType,
|
|
@@ -946,7 +1114,7 @@ declare module 'mongoose' {
|
|
|
946
1114
|
TInstanceMethods & TVirtuals
|
|
947
1115
|
>;
|
|
948
1116
|
where<ResultDoc = THydratedDocumentType>(): QueryWithHelpers<
|
|
949
|
-
|
|
1117
|
+
HasLeanOption<TSchema> extends true ? TRawDocType[] : ResultDoc[],
|
|
950
1118
|
ResultDoc,
|
|
951
1119
|
TQueryHelpers,
|
|
952
1120
|
TRawDocType,
|
package/types/query.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ declare module 'mongoose' {
|
|
|
12
12
|
*/
|
|
13
13
|
type RootFilterQuery<T> = FilterQuery<T> | Query<any, any> | Types.ObjectId;
|
|
14
14
|
|
|
15
|
-
type FilterQuery<T> =
|
|
16
|
-
[P in keyof T]?: Condition<T[P]>;
|
|
17
|
-
|
|
15
|
+
type FilterQuery<T> = IsItRecordAndNotAny<T> extends true ?
|
|
16
|
+
({ [P in keyof T]?: Condition<T[P]>; } & RootQuerySelector<T> & { _id?: Condition<string>; }) :
|
|
17
|
+
FilterQuery<Record<string, any>>;
|
|
18
18
|
|
|
19
19
|
type MongooseBaseQueryOptionKeys =
|
|
20
20
|
| 'context'
|
|
@@ -120,6 +120,17 @@ declare module 'mongoose' {
|
|
|
120
120
|
updatedAt?: boolean;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
// Options that can be passed to Query.prototype.lean()
|
|
124
|
+
interface LeanOptions {
|
|
125
|
+
// Set to false to strip out the version key
|
|
126
|
+
versionKey?: boolean;
|
|
127
|
+
// Transform the result document in place. `doc` is the raw document being transformed.
|
|
128
|
+
// Typed as `Record<string, unknown>` because TypeScript gets confused when handling Document.prototype.deleteOne()
|
|
129
|
+
// and other document methods that try to infer the raw doc type from the Document class.
|
|
130
|
+
transform?: (doc: Record<string, unknown>) => void;
|
|
131
|
+
[key: string]: any;
|
|
132
|
+
}
|
|
133
|
+
|
|
123
134
|
interface QueryOptions<DocType = unknown> extends
|
|
124
135
|
PopulateOption,
|
|
125
136
|
SessionOption {
|
|
@@ -134,7 +145,7 @@ declare module 'mongoose' {
|
|
|
134
145
|
/**
|
|
135
146
|
* If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.
|
|
136
147
|
*/
|
|
137
|
-
lean?: boolean |
|
|
148
|
+
lean?: boolean | LeanOptions;
|
|
138
149
|
limit?: number;
|
|
139
150
|
maxTimeMS?: number;
|
|
140
151
|
multi?: boolean;
|
|
@@ -231,7 +242,7 @@ declare module 'mongoose' {
|
|
|
231
242
|
: MergeType<ResultType, Paths>;
|
|
232
243
|
|
|
233
244
|
class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TDocOverrides = Record<string, never>> implements SessionOperation {
|
|
234
|
-
_mongooseOptions: QueryOptions<
|
|
245
|
+
_mongooseOptions: QueryOptions<RawDocType>;
|
|
235
246
|
|
|
236
247
|
/**
|
|
237
248
|
* Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html).
|
|
@@ -310,14 +321,14 @@ declare module 'mongoose' {
|
|
|
310
321
|
/** Specifies this query as a `countDocuments` query. */
|
|
311
322
|
countDocuments(
|
|
312
323
|
criteria?: RootFilterQuery<RawDocType>,
|
|
313
|
-
options?: QueryOptions<
|
|
324
|
+
options?: QueryOptions<RawDocType>
|
|
314
325
|
): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments', TDocOverrides>;
|
|
315
326
|
|
|
316
327
|
/**
|
|
317
328
|
* Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html).
|
|
318
329
|
* A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
|
|
319
330
|
*/
|
|
320
|
-
cursor(options?: QueryOptions<
|
|
331
|
+
cursor(options?: QueryOptions<RawDocType>): Cursor<Unpacked<ResultType>, QueryOptions<RawDocType>>;
|
|
321
332
|
|
|
322
333
|
/**
|
|
323
334
|
* Declare and/or execute this query as a `deleteMany()` operation. Works like
|
|
@@ -326,7 +337,7 @@ declare module 'mongoose' {
|
|
|
326
337
|
*/
|
|
327
338
|
deleteMany(
|
|
328
339
|
filter?: RootFilterQuery<RawDocType>,
|
|
329
|
-
options?: QueryOptions<
|
|
340
|
+
options?: QueryOptions<RawDocType>
|
|
330
341
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TDocOverrides>;
|
|
331
342
|
deleteMany(filter: RootFilterQuery<RawDocType>): QueryWithHelpers<
|
|
332
343
|
any,
|
|
@@ -345,7 +356,7 @@ declare module 'mongoose' {
|
|
|
345
356
|
*/
|
|
346
357
|
deleteOne(
|
|
347
358
|
filter?: RootFilterQuery<RawDocType>,
|
|
348
|
-
options?: QueryOptions<
|
|
359
|
+
options?: QueryOptions<RawDocType>
|
|
349
360
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TDocOverrides>;
|
|
350
361
|
deleteOne(filter: RootFilterQuery<RawDocType>): QueryWithHelpers<
|
|
351
362
|
any,
|
|
@@ -361,7 +372,7 @@ declare module 'mongoose' {
|
|
|
361
372
|
distinct<DocKey extends string, ResultType = unknown>(
|
|
362
373
|
field: DocKey,
|
|
363
374
|
filter?: RootFilterQuery<RawDocType>,
|
|
364
|
-
options?: QueryOptions<
|
|
375
|
+
options?: QueryOptions<RawDocType>
|
|
365
376
|
): QueryWithHelpers<
|
|
366
377
|
Array<
|
|
367
378
|
DocKey extends keyof WithLevel1NestedPaths<DocType>
|
|
@@ -390,7 +401,7 @@ declare module 'mongoose' {
|
|
|
390
401
|
equals(val: any): this;
|
|
391
402
|
|
|
392
403
|
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
|
|
393
|
-
estimatedDocumentCount(options?: QueryOptions<
|
|
404
|
+
estimatedDocumentCount(options?: QueryOptions<RawDocType>): QueryWithHelpers<
|
|
394
405
|
number,
|
|
395
406
|
DocType,
|
|
396
407
|
THelpers,
|
|
@@ -415,7 +426,7 @@ declare module 'mongoose' {
|
|
|
415
426
|
find(
|
|
416
427
|
filter: RootFilterQuery<RawDocType>,
|
|
417
428
|
projection?: ProjectionType<RawDocType> | null,
|
|
418
|
-
options?: QueryOptions<
|
|
429
|
+
options?: QueryOptions<RawDocType> | null
|
|
419
430
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
|
|
420
431
|
find(
|
|
421
432
|
filter: RootFilterQuery<RawDocType>,
|
|
@@ -430,7 +441,7 @@ declare module 'mongoose' {
|
|
|
430
441
|
findOne(
|
|
431
442
|
filter?: RootFilterQuery<RawDocType>,
|
|
432
443
|
projection?: ProjectionType<RawDocType> | null,
|
|
433
|
-
options?: QueryOptions<
|
|
444
|
+
options?: QueryOptions<RawDocType> | null
|
|
434
445
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
435
446
|
findOne(
|
|
436
447
|
filter?: RootFilterQuery<RawDocType>,
|
|
@@ -443,24 +454,24 @@ declare module 'mongoose' {
|
|
|
443
454
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
444
455
|
findOneAndDelete(
|
|
445
456
|
filter?: RootFilterQuery<RawDocType>,
|
|
446
|
-
options?: QueryOptions<
|
|
457
|
+
options?: QueryOptions<RawDocType> | null
|
|
447
458
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
|
|
448
459
|
|
|
449
460
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
450
461
|
findOneAndUpdate(
|
|
451
462
|
filter: RootFilterQuery<RawDocType>,
|
|
452
463
|
update: UpdateQuery<RawDocType>,
|
|
453
|
-
options: QueryOptions<
|
|
464
|
+
options: QueryOptions<RawDocType> & { includeResultMetadata: true }
|
|
454
465
|
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
455
466
|
findOneAndUpdate(
|
|
456
467
|
filter: RootFilterQuery<RawDocType>,
|
|
457
468
|
update: UpdateQuery<RawDocType>,
|
|
458
|
-
options: QueryOptions<
|
|
469
|
+
options: QueryOptions<RawDocType> & { upsert: true } & ReturnsNewDoc
|
|
459
470
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
460
471
|
findOneAndUpdate(
|
|
461
472
|
filter: RootFilterQuery<RawDocType>,
|
|
462
473
|
update: UpdateQuery<RawDocType>,
|
|
463
|
-
options?: QueryOptions<
|
|
474
|
+
options?: QueryOptions<RawDocType> | null
|
|
464
475
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
465
476
|
findOneAndUpdate(
|
|
466
477
|
update: UpdateQuery<RawDocType>
|
|
@@ -471,7 +482,7 @@ declare module 'mongoose' {
|
|
|
471
482
|
findById(
|
|
472
483
|
id: mongodb.ObjectId | any,
|
|
473
484
|
projection?: ProjectionType<RawDocType> | null,
|
|
474
|
-
options?: QueryOptions<
|
|
485
|
+
options?: QueryOptions<RawDocType> | null
|
|
475
486
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
476
487
|
findById(
|
|
477
488
|
id: mongodb.ObjectId | any,
|
|
@@ -484,28 +495,28 @@ declare module 'mongoose' {
|
|
|
484
495
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
485
496
|
findByIdAndDelete(
|
|
486
497
|
id: mongodb.ObjectId | any,
|
|
487
|
-
options: QueryOptions<
|
|
498
|
+
options: QueryOptions<RawDocType> & { includeResultMetadata: true }
|
|
488
499
|
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndDelete', TDocOverrides>;
|
|
489
500
|
findByIdAndDelete(
|
|
490
501
|
id?: mongodb.ObjectId | any,
|
|
491
|
-
options?: QueryOptions<
|
|
502
|
+
options?: QueryOptions<RawDocType> | null
|
|
492
503
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete', TDocOverrides>;
|
|
493
504
|
|
|
494
505
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
495
506
|
findByIdAndUpdate(
|
|
496
507
|
id: mongodb.ObjectId | any,
|
|
497
508
|
update: UpdateQuery<RawDocType>,
|
|
498
|
-
options: QueryOptions<
|
|
509
|
+
options: QueryOptions<RawDocType> & { includeResultMetadata: true }
|
|
499
510
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
500
511
|
findByIdAndUpdate(
|
|
501
512
|
id: mongodb.ObjectId | any,
|
|
502
513
|
update: UpdateQuery<RawDocType>,
|
|
503
|
-
options: QueryOptions<
|
|
514
|
+
options: QueryOptions<RawDocType> & { upsert: true } & ReturnsNewDoc
|
|
504
515
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
505
516
|
findByIdAndUpdate(
|
|
506
517
|
id?: mongodb.ObjectId | any,
|
|
507
518
|
update?: UpdateQuery<RawDocType>,
|
|
508
|
-
options?: QueryOptions<
|
|
519
|
+
options?: QueryOptions<RawDocType> | null
|
|
509
520
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
510
521
|
findByIdAndUpdate(
|
|
511
522
|
id: mongodb.ObjectId | any,
|
|
@@ -526,7 +537,7 @@ declare module 'mongoose' {
|
|
|
526
537
|
getFilter(): FilterQuery<RawDocType>;
|
|
527
538
|
|
|
528
539
|
/** Gets query options. */
|
|
529
|
-
getOptions(): QueryOptions<
|
|
540
|
+
getOptions(): QueryOptions<RawDocType>;
|
|
530
541
|
|
|
531
542
|
/** Gets a list of paths to be populated by this query */
|
|
532
543
|
getPopulatedPaths(): Array<string>;
|
|
@@ -559,8 +570,18 @@ declare module 'mongoose' {
|
|
|
559
570
|
j(val: boolean | null): this;
|
|
560
571
|
|
|
561
572
|
/** Sets the lean option. */
|
|
573
|
+
lean(): QueryWithHelpers<
|
|
574
|
+
ResultType extends null
|
|
575
|
+
? GetLeanResultType<RawDocType, ResultType, QueryOp> | null
|
|
576
|
+
: GetLeanResultType<RawDocType, ResultType, QueryOp>,
|
|
577
|
+
DocType,
|
|
578
|
+
THelpers,
|
|
579
|
+
RawDocType,
|
|
580
|
+
QueryOp,
|
|
581
|
+
TDocOverrides
|
|
582
|
+
>;
|
|
562
583
|
lean(
|
|
563
|
-
val
|
|
584
|
+
val: true | LeanOptions
|
|
564
585
|
): QueryWithHelpers<
|
|
565
586
|
ResultType extends null
|
|
566
587
|
? GetLeanResultType<RawDocType, ResultType, QueryOp> | null
|
|
@@ -571,8 +592,32 @@ declare module 'mongoose' {
|
|
|
571
592
|
QueryOp,
|
|
572
593
|
TDocOverrides
|
|
573
594
|
>;
|
|
595
|
+
lean(
|
|
596
|
+
val: false
|
|
597
|
+
): QueryWithHelpers<
|
|
598
|
+
ResultType extends AnyArray<any>
|
|
599
|
+
? DocType[]
|
|
600
|
+
: ResultType extends null
|
|
601
|
+
? DocType | null
|
|
602
|
+
: DocType,
|
|
603
|
+
DocType,
|
|
604
|
+
THelpers,
|
|
605
|
+
RawDocType,
|
|
606
|
+
QueryOp,
|
|
607
|
+
TDocOverrides
|
|
608
|
+
>;
|
|
609
|
+
lean<LeanResultType>(): QueryWithHelpers<
|
|
610
|
+
ResultType extends null
|
|
611
|
+
? LeanResultType | null
|
|
612
|
+
: LeanResultType,
|
|
613
|
+
DocType,
|
|
614
|
+
THelpers,
|
|
615
|
+
RawDocType,
|
|
616
|
+
QueryOp,
|
|
617
|
+
TDocOverrides
|
|
618
|
+
>;
|
|
574
619
|
lean<LeanResultType>(
|
|
575
|
-
val
|
|
620
|
+
val: boolean | LeanOptions
|
|
576
621
|
): QueryWithHelpers<
|
|
577
622
|
ResultType extends null
|
|
578
623
|
? LeanResultType | null
|
|
@@ -626,7 +671,7 @@ declare module 'mongoose' {
|
|
|
626
671
|
* Getter/setter around the current mongoose-specific options for this query
|
|
627
672
|
* Below are the current Mongoose-specific options.
|
|
628
673
|
*/
|
|
629
|
-
mongooseOptions(val?: QueryOptions<
|
|
674
|
+
mongooseOptions(val?: QueryOptions<RawDocType>): QueryOptions<RawDocType>;
|
|
630
675
|
|
|
631
676
|
/** Specifies a `$ne` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
632
677
|
ne<K = string>(path: K, val: any): this;
|
|
@@ -734,7 +779,7 @@ declare module 'mongoose' {
|
|
|
734
779
|
replaceOne(
|
|
735
780
|
filter?: RootFilterQuery<RawDocType>,
|
|
736
781
|
replacement?: DocType | AnyObject,
|
|
737
|
-
options?: QueryOptions<
|
|
782
|
+
options?: QueryOptions<RawDocType> | null
|
|
738
783
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne', TDocOverrides>;
|
|
739
784
|
|
|
740
785
|
/**
|
|
@@ -800,7 +845,7 @@ declare module 'mongoose' {
|
|
|
800
845
|
set(path: string | Record<string, unknown>, value?: any): this;
|
|
801
846
|
|
|
802
847
|
/** Sets query options. Some options only make sense for certain operations. */
|
|
803
|
-
setOptions(options: QueryOptions<
|
|
848
|
+
setOptions(options: QueryOptions<RawDocType>, overwrite?: boolean): this;
|
|
804
849
|
|
|
805
850
|
/** Sets the query conditions to the provided JSON object. */
|
|
806
851
|
setQuery(val: FilterQuery<RawDocType> | null): void;
|
|
@@ -848,7 +893,7 @@ declare module 'mongoose' {
|
|
|
848
893
|
updateMany(
|
|
849
894
|
filter: RootFilterQuery<RawDocType>,
|
|
850
895
|
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
851
|
-
options?: QueryOptions<
|
|
896
|
+
options?: QueryOptions<RawDocType> | null
|
|
852
897
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany', TDocOverrides>;
|
|
853
898
|
updateMany(
|
|
854
899
|
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline
|
|
@@ -861,7 +906,7 @@ declare module 'mongoose' {
|
|
|
861
906
|
updateOne(
|
|
862
907
|
filter: RootFilterQuery<RawDocType>,
|
|
863
908
|
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
864
|
-
options?: QueryOptions<
|
|
909
|
+
options?: QueryOptions<RawDocType> | null
|
|
865
910
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne', TDocOverrides>;
|
|
866
911
|
updateOne(
|
|
867
912
|
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline
|
package/types/schemaoptions.d.ts
CHANGED
|
@@ -58,6 +58,9 @@ declare module 'mongoose' {
|
|
|
58
58
|
/** Arbitrary options passed to `createCollection()` */
|
|
59
59
|
collectionOptions?: mongodb.CreateCollectionOptions;
|
|
60
60
|
|
|
61
|
+
/** Default lean options for queries */
|
|
62
|
+
lean?: boolean | LeanOptions;
|
|
63
|
+
|
|
61
64
|
/** The timeseries option to use when creating the model's collection. */
|
|
62
65
|
timeseries?: mongodb.TimeSeriesCollectionOptions;
|
|
63
66
|
|