mongoose 8.18.2 → 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/connection.js +1 -1
- package/lib/document.js +6 -2
- package/lib/helpers/query/castUpdate.js +3 -3
- package/lib/helpers/schema/getPath.js +4 -1
- package/lib/model.js +16 -5
- package/lib/mongoose.js +2 -2
- 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 +79 -32
- 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'
|
|
@@ -31,7 +31,9 @@ declare module 'mongoose' {
|
|
|
31
31
|
| 'strictQuery'
|
|
32
32
|
| 'translateAliases';
|
|
33
33
|
|
|
34
|
-
type MongooseBaseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, MongooseBaseQueryOptionKeys
|
|
34
|
+
type MongooseBaseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, MongooseBaseQueryOptionKeys | 'timestamps' | 'lean'> & {
|
|
35
|
+
[other: string]: any;
|
|
36
|
+
};
|
|
35
37
|
|
|
36
38
|
type MongooseUpdateQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, MongooseBaseQueryOptionKeys | 'timestamps'>;
|
|
37
39
|
|
|
@@ -118,6 +120,17 @@ declare module 'mongoose' {
|
|
|
118
120
|
updatedAt?: boolean;
|
|
119
121
|
}
|
|
120
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
|
+
|
|
121
134
|
interface QueryOptions<DocType = unknown> extends
|
|
122
135
|
PopulateOption,
|
|
123
136
|
SessionOption {
|
|
@@ -132,7 +145,7 @@ declare module 'mongoose' {
|
|
|
132
145
|
/**
|
|
133
146
|
* If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.
|
|
134
147
|
*/
|
|
135
|
-
lean?: boolean |
|
|
148
|
+
lean?: boolean | LeanOptions;
|
|
136
149
|
limit?: number;
|
|
137
150
|
maxTimeMS?: number;
|
|
138
151
|
multi?: boolean;
|
|
@@ -229,7 +242,7 @@ declare module 'mongoose' {
|
|
|
229
242
|
: MergeType<ResultType, Paths>;
|
|
230
243
|
|
|
231
244
|
class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TDocOverrides = Record<string, never>> implements SessionOperation {
|
|
232
|
-
_mongooseOptions: QueryOptions<
|
|
245
|
+
_mongooseOptions: QueryOptions<RawDocType>;
|
|
233
246
|
|
|
234
247
|
/**
|
|
235
248
|
* Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html).
|
|
@@ -308,14 +321,14 @@ declare module 'mongoose' {
|
|
|
308
321
|
/** Specifies this query as a `countDocuments` query. */
|
|
309
322
|
countDocuments(
|
|
310
323
|
criteria?: RootFilterQuery<RawDocType>,
|
|
311
|
-
options?: QueryOptions<
|
|
324
|
+
options?: QueryOptions<RawDocType>
|
|
312
325
|
): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments', TDocOverrides>;
|
|
313
326
|
|
|
314
327
|
/**
|
|
315
328
|
* Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html).
|
|
316
329
|
* A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
|
|
317
330
|
*/
|
|
318
|
-
cursor(options?: QueryOptions<
|
|
331
|
+
cursor(options?: QueryOptions<RawDocType>): Cursor<Unpacked<ResultType>, QueryOptions<RawDocType>>;
|
|
319
332
|
|
|
320
333
|
/**
|
|
321
334
|
* Declare and/or execute this query as a `deleteMany()` operation. Works like
|
|
@@ -324,7 +337,7 @@ declare module 'mongoose' {
|
|
|
324
337
|
*/
|
|
325
338
|
deleteMany(
|
|
326
339
|
filter?: RootFilterQuery<RawDocType>,
|
|
327
|
-
options?: QueryOptions<
|
|
340
|
+
options?: QueryOptions<RawDocType>
|
|
328
341
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TDocOverrides>;
|
|
329
342
|
deleteMany(filter: RootFilterQuery<RawDocType>): QueryWithHelpers<
|
|
330
343
|
any,
|
|
@@ -343,7 +356,7 @@ declare module 'mongoose' {
|
|
|
343
356
|
*/
|
|
344
357
|
deleteOne(
|
|
345
358
|
filter?: RootFilterQuery<RawDocType>,
|
|
346
|
-
options?: QueryOptions<
|
|
359
|
+
options?: QueryOptions<RawDocType>
|
|
347
360
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TDocOverrides>;
|
|
348
361
|
deleteOne(filter: RootFilterQuery<RawDocType>): QueryWithHelpers<
|
|
349
362
|
any,
|
|
@@ -359,7 +372,7 @@ declare module 'mongoose' {
|
|
|
359
372
|
distinct<DocKey extends string, ResultType = unknown>(
|
|
360
373
|
field: DocKey,
|
|
361
374
|
filter?: RootFilterQuery<RawDocType>,
|
|
362
|
-
options?: QueryOptions<
|
|
375
|
+
options?: QueryOptions<RawDocType>
|
|
363
376
|
): QueryWithHelpers<
|
|
364
377
|
Array<
|
|
365
378
|
DocKey extends keyof WithLevel1NestedPaths<DocType>
|
|
@@ -388,7 +401,7 @@ declare module 'mongoose' {
|
|
|
388
401
|
equals(val: any): this;
|
|
389
402
|
|
|
390
403
|
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
|
|
391
|
-
estimatedDocumentCount(options?: QueryOptions<
|
|
404
|
+
estimatedDocumentCount(options?: QueryOptions<RawDocType>): QueryWithHelpers<
|
|
392
405
|
number,
|
|
393
406
|
DocType,
|
|
394
407
|
THelpers,
|
|
@@ -413,7 +426,7 @@ declare module 'mongoose' {
|
|
|
413
426
|
find(
|
|
414
427
|
filter: RootFilterQuery<RawDocType>,
|
|
415
428
|
projection?: ProjectionType<RawDocType> | null,
|
|
416
|
-
options?: QueryOptions<
|
|
429
|
+
options?: QueryOptions<RawDocType> | null
|
|
417
430
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
|
|
418
431
|
find(
|
|
419
432
|
filter: RootFilterQuery<RawDocType>,
|
|
@@ -428,7 +441,7 @@ declare module 'mongoose' {
|
|
|
428
441
|
findOne(
|
|
429
442
|
filter?: RootFilterQuery<RawDocType>,
|
|
430
443
|
projection?: ProjectionType<RawDocType> | null,
|
|
431
|
-
options?: QueryOptions<
|
|
444
|
+
options?: QueryOptions<RawDocType> | null
|
|
432
445
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
433
446
|
findOne(
|
|
434
447
|
filter?: RootFilterQuery<RawDocType>,
|
|
@@ -441,24 +454,24 @@ declare module 'mongoose' {
|
|
|
441
454
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
442
455
|
findOneAndDelete(
|
|
443
456
|
filter?: RootFilterQuery<RawDocType>,
|
|
444
|
-
options?: QueryOptions<
|
|
457
|
+
options?: QueryOptions<RawDocType> | null
|
|
445
458
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
|
|
446
459
|
|
|
447
460
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
448
461
|
findOneAndUpdate(
|
|
449
462
|
filter: RootFilterQuery<RawDocType>,
|
|
450
463
|
update: UpdateQuery<RawDocType>,
|
|
451
|
-
options: QueryOptions<
|
|
464
|
+
options: QueryOptions<RawDocType> & { includeResultMetadata: true }
|
|
452
465
|
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
453
466
|
findOneAndUpdate(
|
|
454
467
|
filter: RootFilterQuery<RawDocType>,
|
|
455
468
|
update: UpdateQuery<RawDocType>,
|
|
456
|
-
options: QueryOptions<
|
|
469
|
+
options: QueryOptions<RawDocType> & { upsert: true } & ReturnsNewDoc
|
|
457
470
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
458
471
|
findOneAndUpdate(
|
|
459
472
|
filter: RootFilterQuery<RawDocType>,
|
|
460
473
|
update: UpdateQuery<RawDocType>,
|
|
461
|
-
options?: QueryOptions<
|
|
474
|
+
options?: QueryOptions<RawDocType> | null
|
|
462
475
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
463
476
|
findOneAndUpdate(
|
|
464
477
|
update: UpdateQuery<RawDocType>
|
|
@@ -469,7 +482,7 @@ declare module 'mongoose' {
|
|
|
469
482
|
findById(
|
|
470
483
|
id: mongodb.ObjectId | any,
|
|
471
484
|
projection?: ProjectionType<RawDocType> | null,
|
|
472
|
-
options?: QueryOptions<
|
|
485
|
+
options?: QueryOptions<RawDocType> | null
|
|
473
486
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
474
487
|
findById(
|
|
475
488
|
id: mongodb.ObjectId | any,
|
|
@@ -482,28 +495,28 @@ declare module 'mongoose' {
|
|
|
482
495
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
483
496
|
findByIdAndDelete(
|
|
484
497
|
id: mongodb.ObjectId | any,
|
|
485
|
-
options: QueryOptions<
|
|
498
|
+
options: QueryOptions<RawDocType> & { includeResultMetadata: true }
|
|
486
499
|
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndDelete', TDocOverrides>;
|
|
487
500
|
findByIdAndDelete(
|
|
488
501
|
id?: mongodb.ObjectId | any,
|
|
489
|
-
options?: QueryOptions<
|
|
502
|
+
options?: QueryOptions<RawDocType> | null
|
|
490
503
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete', TDocOverrides>;
|
|
491
504
|
|
|
492
505
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
493
506
|
findByIdAndUpdate(
|
|
494
507
|
id: mongodb.ObjectId | any,
|
|
495
508
|
update: UpdateQuery<RawDocType>,
|
|
496
|
-
options: QueryOptions<
|
|
509
|
+
options: QueryOptions<RawDocType> & { includeResultMetadata: true }
|
|
497
510
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
498
511
|
findByIdAndUpdate(
|
|
499
512
|
id: mongodb.ObjectId | any,
|
|
500
513
|
update: UpdateQuery<RawDocType>,
|
|
501
|
-
options: QueryOptions<
|
|
514
|
+
options: QueryOptions<RawDocType> & { upsert: true } & ReturnsNewDoc
|
|
502
515
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
503
516
|
findByIdAndUpdate(
|
|
504
517
|
id?: mongodb.ObjectId | any,
|
|
505
518
|
update?: UpdateQuery<RawDocType>,
|
|
506
|
-
options?: QueryOptions<
|
|
519
|
+
options?: QueryOptions<RawDocType> | null
|
|
507
520
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
|
|
508
521
|
findByIdAndUpdate(
|
|
509
522
|
id: mongodb.ObjectId | any,
|
|
@@ -524,7 +537,7 @@ declare module 'mongoose' {
|
|
|
524
537
|
getFilter(): FilterQuery<RawDocType>;
|
|
525
538
|
|
|
526
539
|
/** Gets query options. */
|
|
527
|
-
getOptions(): QueryOptions<
|
|
540
|
+
getOptions(): QueryOptions<RawDocType>;
|
|
528
541
|
|
|
529
542
|
/** Gets a list of paths to be populated by this query */
|
|
530
543
|
getPopulatedPaths(): Array<string>;
|
|
@@ -557,8 +570,18 @@ declare module 'mongoose' {
|
|
|
557
570
|
j(val: boolean | null): this;
|
|
558
571
|
|
|
559
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
|
+
>;
|
|
560
583
|
lean(
|
|
561
|
-
val
|
|
584
|
+
val: true | LeanOptions
|
|
562
585
|
): QueryWithHelpers<
|
|
563
586
|
ResultType extends null
|
|
564
587
|
? GetLeanResultType<RawDocType, ResultType, QueryOp> | null
|
|
@@ -569,8 +592,32 @@ declare module 'mongoose' {
|
|
|
569
592
|
QueryOp,
|
|
570
593
|
TDocOverrides
|
|
571
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
|
+
>;
|
|
572
619
|
lean<LeanResultType>(
|
|
573
|
-
val
|
|
620
|
+
val: boolean | LeanOptions
|
|
574
621
|
): QueryWithHelpers<
|
|
575
622
|
ResultType extends null
|
|
576
623
|
? LeanResultType | null
|
|
@@ -624,7 +671,7 @@ declare module 'mongoose' {
|
|
|
624
671
|
* Getter/setter around the current mongoose-specific options for this query
|
|
625
672
|
* Below are the current Mongoose-specific options.
|
|
626
673
|
*/
|
|
627
|
-
mongooseOptions(val?: QueryOptions<
|
|
674
|
+
mongooseOptions(val?: QueryOptions<RawDocType>): QueryOptions<RawDocType>;
|
|
628
675
|
|
|
629
676
|
/** Specifies a `$ne` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
630
677
|
ne<K = string>(path: K, val: any): this;
|
|
@@ -732,7 +779,7 @@ declare module 'mongoose' {
|
|
|
732
779
|
replaceOne(
|
|
733
780
|
filter?: RootFilterQuery<RawDocType>,
|
|
734
781
|
replacement?: DocType | AnyObject,
|
|
735
|
-
options?: QueryOptions<
|
|
782
|
+
options?: QueryOptions<RawDocType> | null
|
|
736
783
|
): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne', TDocOverrides>;
|
|
737
784
|
|
|
738
785
|
/**
|
|
@@ -798,7 +845,7 @@ declare module 'mongoose' {
|
|
|
798
845
|
set(path: string | Record<string, unknown>, value?: any): this;
|
|
799
846
|
|
|
800
847
|
/** Sets query options. Some options only make sense for certain operations. */
|
|
801
|
-
setOptions(options: QueryOptions<
|
|
848
|
+
setOptions(options: QueryOptions<RawDocType>, overwrite?: boolean): this;
|
|
802
849
|
|
|
803
850
|
/** Sets the query conditions to the provided JSON object. */
|
|
804
851
|
setQuery(val: FilterQuery<RawDocType> | null): void;
|
|
@@ -846,7 +893,7 @@ declare module 'mongoose' {
|
|
|
846
893
|
updateMany(
|
|
847
894
|
filter: RootFilterQuery<RawDocType>,
|
|
848
895
|
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
849
|
-
options?: QueryOptions<
|
|
896
|
+
options?: QueryOptions<RawDocType> | null
|
|
850
897
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany', TDocOverrides>;
|
|
851
898
|
updateMany(
|
|
852
899
|
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline
|
|
@@ -859,7 +906,7 @@ declare module 'mongoose' {
|
|
|
859
906
|
updateOne(
|
|
860
907
|
filter: RootFilterQuery<RawDocType>,
|
|
861
908
|
update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
|
|
862
|
-
options?: QueryOptions<
|
|
909
|
+
options?: QueryOptions<RawDocType> | null
|
|
863
910
|
): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne', TDocOverrides>;
|
|
864
911
|
updateOne(
|
|
865
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
|
|