mongoose 9.9.0 → 9.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/queryHelpers.js +22 -0
- package/package.json +1 -1
- package/types/models.d.ts +133 -4
package/lib/queryHelpers.js
CHANGED
|
@@ -209,6 +209,13 @@ exports.applyPaths = function applyPaths(fields, schema, sanitizeProjection) {
|
|
|
209
209
|
switch (exclude) {
|
|
210
210
|
case true:
|
|
211
211
|
for (const fieldName of excluded) {
|
|
212
|
+
// Skip if an ancestor path is already excluded in `fields` (for
|
|
213
|
+
// example the user did `.select('-subd')` and `subd.raw` has
|
|
214
|
+
// schema-level `select: false`) to avoid MongoDB's "Path collision"
|
|
215
|
+
// error from projecting both `subd` and `subd.raw`. See gh-12798
|
|
216
|
+
if (hasExcludedAncestor(fields, fieldName)) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
212
219
|
fields[fieldName] = 0;
|
|
213
220
|
}
|
|
214
221
|
break;
|
|
@@ -372,6 +379,21 @@ exports.applyPaths = function applyPaths(fields, schema, sanitizeProjection) {
|
|
|
372
379
|
(type.selected ? selected : excluded).push(path);
|
|
373
380
|
return path;
|
|
374
381
|
}
|
|
382
|
+
|
|
383
|
+
function hasExcludedAncestor(fields, path) {
|
|
384
|
+
let i = -1;
|
|
385
|
+
while ((i = path.indexOf('.', i + 1)) !== -1) {
|
|
386
|
+
const ancestor = fields[path.slice(0, i)];
|
|
387
|
+
// Any falsy defining value (`0`, `false`, `''`, `NaN`) excludes a
|
|
388
|
+
// path, matching how `exclude` itself is derived above (`!field`).
|
|
389
|
+
// `ancestor == null` means the key isn't present at all, which is
|
|
390
|
+
// not an exclusion. See gh-12798
|
|
391
|
+
if (ancestor != null && !ancestor) {
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
375
397
|
};
|
|
376
398
|
|
|
377
399
|
/**
|
package/package.json
CHANGED
package/types/models.d.ts
CHANGED
|
@@ -457,6 +457,18 @@ declare module 'mongoose' {
|
|
|
457
457
|
'findOne',
|
|
458
458
|
TInstanceMethods & TVirtuals
|
|
459
459
|
>;
|
|
460
|
+
findById<ResultDoc = THydratedDocumentType>(
|
|
461
|
+
id: any,
|
|
462
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
463
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
464
|
+
): QueryWithHelpers<
|
|
465
|
+
ResultDoc | null,
|
|
466
|
+
ResultDoc,
|
|
467
|
+
TQueryHelpers,
|
|
468
|
+
TLeanResultType,
|
|
469
|
+
'findOne',
|
|
470
|
+
TInstanceMethods & TVirtuals
|
|
471
|
+
>;
|
|
460
472
|
findById<ResultDoc = THydratedDocumentType>(
|
|
461
473
|
id?: any,
|
|
462
474
|
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
@@ -495,6 +507,18 @@ declare module 'mongoose' {
|
|
|
495
507
|
'findOne',
|
|
496
508
|
TInstanceMethods & TVirtuals
|
|
497
509
|
>;
|
|
510
|
+
findOne<ResultDoc = THydratedDocumentType>(
|
|
511
|
+
filter: QueryFilter<TRawDocType>,
|
|
512
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
513
|
+
options: QueryOptions<TRawDocType> & { lean: false } & mongodb.Abortable
|
|
514
|
+
): QueryWithHelpers<
|
|
515
|
+
ResultDoc | null,
|
|
516
|
+
ResultDoc,
|
|
517
|
+
TQueryHelpers,
|
|
518
|
+
TLeanResultType,
|
|
519
|
+
'findOne',
|
|
520
|
+
TInstanceMethods & TVirtuals
|
|
521
|
+
>;
|
|
498
522
|
findOne<ResultDoc = THydratedDocumentType>(
|
|
499
523
|
filter?: QueryFilter<TRawDocType>,
|
|
500
524
|
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
@@ -780,12 +804,24 @@ declare module 'mongoose' {
|
|
|
780
804
|
'find',
|
|
781
805
|
TInstanceMethods & TVirtuals
|
|
782
806
|
>;
|
|
807
|
+
find<ResultDoc = THydratedDocumentType>(
|
|
808
|
+
filter: QueryFilter<TRawDocType>,
|
|
809
|
+
projection: ProjectionType<TRawDocType> | null | undefined,
|
|
810
|
+
options: QueryOptions<TRawDocType> & { lean: false } & mongodb.Abortable
|
|
811
|
+
): QueryWithHelpers<
|
|
812
|
+
ResultDoc[],
|
|
813
|
+
ResultDoc,
|
|
814
|
+
TQueryHelpers,
|
|
815
|
+
TLeanResultType,
|
|
816
|
+
'find',
|
|
817
|
+
TInstanceMethods & TVirtuals
|
|
818
|
+
>;
|
|
783
819
|
find<ResultDoc = THydratedDocumentType>(
|
|
784
820
|
filter?: QueryFilter<TRawDocType>,
|
|
785
821
|
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
786
822
|
options?: QueryOptions<TRawDocType> & mongodb.Abortable
|
|
787
823
|
): QueryWithHelpers<
|
|
788
|
-
ResultDoc[],
|
|
824
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType[] : ResultDoc[],
|
|
789
825
|
ResultDoc,
|
|
790
826
|
TQueryHelpers,
|
|
791
827
|
TLeanResultType,
|
|
@@ -797,7 +833,7 @@ declare module 'mongoose' {
|
|
|
797
833
|
projection?: ProjectionType<TRawDocType> | null | undefined,
|
|
798
834
|
options?: QueryOptions<TRawDocType> & mongodb.Abortable
|
|
799
835
|
): QueryWithHelpers<
|
|
800
|
-
THydratedDocumentType[],
|
|
836
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType[] : THydratedDocumentType[],
|
|
801
837
|
THydratedDocumentType,
|
|
802
838
|
TQueryHelpers,
|
|
803
839
|
TLeanResultType,
|
|
@@ -828,6 +864,17 @@ declare module 'mongoose' {
|
|
|
828
864
|
'findOneAndDelete',
|
|
829
865
|
TInstanceMethods & TVirtuals
|
|
830
866
|
>;
|
|
867
|
+
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
868
|
+
id: mongodb.ObjectId | any,
|
|
869
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
870
|
+
): QueryWithHelpers<
|
|
871
|
+
ResultDoc | null,
|
|
872
|
+
ResultDoc,
|
|
873
|
+
TQueryHelpers,
|
|
874
|
+
TLeanResultType,
|
|
875
|
+
'findOneAndDelete',
|
|
876
|
+
TInstanceMethods & TVirtuals
|
|
877
|
+
>;
|
|
831
878
|
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
|
|
832
879
|
id: mongodb.ObjectId | any,
|
|
833
880
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
@@ -889,6 +936,18 @@ declare module 'mongoose' {
|
|
|
889
936
|
'findOneAndUpdate',
|
|
890
937
|
TInstanceMethods & TVirtuals
|
|
891
938
|
>;
|
|
939
|
+
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
940
|
+
id: mongodb.ObjectId | any,
|
|
941
|
+
update: UpdateQuery<TRawDocType>,
|
|
942
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
943
|
+
): QueryWithHelpers<
|
|
944
|
+
ResultDoc | null,
|
|
945
|
+
ResultDoc,
|
|
946
|
+
TQueryHelpers,
|
|
947
|
+
TLeanResultType,
|
|
948
|
+
'findOneAndUpdate',
|
|
949
|
+
TInstanceMethods & TVirtuals
|
|
950
|
+
>;
|
|
892
951
|
findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
893
952
|
id: mongodb.ObjectId | any,
|
|
894
953
|
update: UpdateQuery<TRawDocType>,
|
|
@@ -949,6 +1008,28 @@ declare module 'mongoose' {
|
|
|
949
1008
|
'findOneAndDelete',
|
|
950
1009
|
TInstanceMethods & TVirtuals
|
|
951
1010
|
>;
|
|
1011
|
+
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
1012
|
+
filter: QueryFilter<TRawDocType>,
|
|
1013
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1014
|
+
): QueryWithHelpers<
|
|
1015
|
+
ResultDoc | null,
|
|
1016
|
+
ResultDoc,
|
|
1017
|
+
TQueryHelpers,
|
|
1018
|
+
TLeanResultType,
|
|
1019
|
+
'findOneAndDelete',
|
|
1020
|
+
TInstanceMethods & TVirtuals
|
|
1021
|
+
>;
|
|
1022
|
+
findOneAndDelete(
|
|
1023
|
+
filter: Query<any, any>,
|
|
1024
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1025
|
+
): QueryWithHelpers<
|
|
1026
|
+
THydratedDocumentType | null,
|
|
1027
|
+
THydratedDocumentType,
|
|
1028
|
+
TQueryHelpers,
|
|
1029
|
+
TLeanResultType,
|
|
1030
|
+
'findOneAndDelete',
|
|
1031
|
+
TInstanceMethods & TVirtuals
|
|
1032
|
+
>;
|
|
952
1033
|
findOneAndDelete<ResultDoc = THydratedDocumentType>(
|
|
953
1034
|
filter: QueryFilter<TRawDocType>,
|
|
954
1035
|
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
|
|
@@ -975,7 +1056,7 @@ declare module 'mongoose' {
|
|
|
975
1056
|
filter?: QueryFilter<TRawDocType> | null,
|
|
976
1057
|
options?: QueryOptions<TRawDocType> | null
|
|
977
1058
|
): QueryWithHelpers<
|
|
978
|
-
HasLeanOption<TSchema> extends true ?
|
|
1059
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : ResultDoc | null,
|
|
979
1060
|
ResultDoc,
|
|
980
1061
|
TQueryHelpers,
|
|
981
1062
|
TLeanResultType,
|
|
@@ -986,7 +1067,7 @@ declare module 'mongoose' {
|
|
|
986
1067
|
filter?: Query<any, any> | null,
|
|
987
1068
|
options?: QueryOptions<TRawDocType> | null
|
|
988
1069
|
): QueryWithHelpers<
|
|
989
|
-
HasLeanOption<TSchema> extends true ?
|
|
1070
|
+
HasLeanOption<TSchema> extends true ? TLeanResultType | null : THydratedDocumentType | null,
|
|
990
1071
|
THydratedDocumentType,
|
|
991
1072
|
TQueryHelpers,
|
|
992
1073
|
TLeanResultType,
|
|
@@ -1019,6 +1100,30 @@ declare module 'mongoose' {
|
|
|
1019
1100
|
'findOneAndReplace',
|
|
1020
1101
|
TInstanceMethods & TVirtuals
|
|
1021
1102
|
>;
|
|
1103
|
+
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
1104
|
+
filter: QueryFilter<TRawDocType>,
|
|
1105
|
+
replacement: TRawDocType | AnyObject,
|
|
1106
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1107
|
+
): QueryWithHelpers<
|
|
1108
|
+
ResultDoc | null,
|
|
1109
|
+
ResultDoc,
|
|
1110
|
+
TQueryHelpers,
|
|
1111
|
+
TLeanResultType,
|
|
1112
|
+
'findOneAndReplace',
|
|
1113
|
+
TInstanceMethods & TVirtuals
|
|
1114
|
+
>;
|
|
1115
|
+
findOneAndReplace(
|
|
1116
|
+
filter: Query<any, any>,
|
|
1117
|
+
replacement: TRawDocType | AnyObject,
|
|
1118
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1119
|
+
): QueryWithHelpers<
|
|
1120
|
+
THydratedDocumentType | null,
|
|
1121
|
+
THydratedDocumentType,
|
|
1122
|
+
TQueryHelpers,
|
|
1123
|
+
TLeanResultType,
|
|
1124
|
+
'findOneAndReplace',
|
|
1125
|
+
TInstanceMethods & TVirtuals
|
|
1126
|
+
>;
|
|
1022
1127
|
findOneAndReplace<ResultDoc = THydratedDocumentType>(
|
|
1023
1128
|
filter: QueryFilter<TRawDocType>,
|
|
1024
1129
|
replacement: TRawDocType | AnyObject,
|
|
@@ -1141,6 +1246,30 @@ declare module 'mongoose' {
|
|
|
1141
1246
|
'findOneAndUpdate',
|
|
1142
1247
|
TInstanceMethods & TVirtuals
|
|
1143
1248
|
>;
|
|
1249
|
+
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1250
|
+
filter: QueryFilter<TRawDocType>,
|
|
1251
|
+
update: UpdateQuery<TRawDocType>,
|
|
1252
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1253
|
+
): QueryWithHelpers<
|
|
1254
|
+
ResultDoc | null,
|
|
1255
|
+
ResultDoc,
|
|
1256
|
+
TQueryHelpers,
|
|
1257
|
+
TLeanResultType,
|
|
1258
|
+
'findOneAndUpdate',
|
|
1259
|
+
TInstanceMethods & TVirtuals
|
|
1260
|
+
>;
|
|
1261
|
+
findOneAndUpdate(
|
|
1262
|
+
filter: Query<any, any>,
|
|
1263
|
+
update: UpdateQuery<TRawDocType>,
|
|
1264
|
+
options: QueryOptions<TRawDocType> & { lean: false }
|
|
1265
|
+
): QueryWithHelpers<
|
|
1266
|
+
THydratedDocumentType | null,
|
|
1267
|
+
THydratedDocumentType,
|
|
1268
|
+
TQueryHelpers,
|
|
1269
|
+
TLeanResultType,
|
|
1270
|
+
'findOneAndUpdate',
|
|
1271
|
+
TInstanceMethods & TVirtuals
|
|
1272
|
+
>;
|
|
1144
1273
|
findOneAndUpdate<ResultDoc = THydratedDocumentType>(
|
|
1145
1274
|
filter: QueryFilter<TRawDocType>,
|
|
1146
1275
|
update: UpdateQuery<TRawDocType>,
|