mongoose 6.13.8 → 6.13.10
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/document.js
CHANGED
|
@@ -58,6 +58,7 @@ let MongooseArray;
|
|
|
58
58
|
let Embedded;
|
|
59
59
|
|
|
60
60
|
const specialProperties = utils.specialProperties;
|
|
61
|
+
const hasOwnProperty = utils.object.hasOwnProperty;
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
64
|
* The core Mongoose document constructor. You should not call this directly,
|
|
@@ -1869,7 +1870,9 @@ Document.prototype.get = function(path, type, options) {
|
|
|
1869
1870
|
|
|
1870
1871
|
// Fast path if we know we're just accessing top-level path on the document:
|
|
1871
1872
|
// just get the schema path, avoid `$__path()` because that does string manipulation
|
|
1872
|
-
let schema = noDottedPath ?
|
|
1873
|
+
let schema = noDottedPath ?
|
|
1874
|
+
hasOwnProperty(this.$__schema.paths, path) ? this.$__schema.paths[path] : undefined :
|
|
1875
|
+
this.$__path(path);
|
|
1873
1876
|
if (schema == null) {
|
|
1874
1877
|
schema = this.$__schema.virtualpath(path);
|
|
1875
1878
|
|
|
@@ -1879,7 +1882,7 @@ Document.prototype.get = function(path, type, options) {
|
|
|
1879
1882
|
}
|
|
1880
1883
|
|
|
1881
1884
|
if (noDottedPath) {
|
|
1882
|
-
let obj = this._doc[path];
|
|
1885
|
+
let obj = hasOwnProperty(this._doc, path) ? this._doc[path] : undefined;
|
|
1883
1886
|
if (adhoc) {
|
|
1884
1887
|
obj = adhoc.cast(obj);
|
|
1885
1888
|
}
|
|
@@ -1906,6 +1909,10 @@ Document.prototype.get = function(path, type, options) {
|
|
|
1906
1909
|
}
|
|
1907
1910
|
|
|
1908
1911
|
for (let i = 0, l = pieces.length; i < l; i++) {
|
|
1912
|
+
if (specialProperties.has(pieces[i])) {
|
|
1913
|
+
return undefined;
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1909
1916
|
if (obj && obj._doc) {
|
|
1910
1917
|
obj = obj._doc;
|
|
1911
1918
|
}
|
|
@@ -1927,7 +1934,7 @@ Document.prototype.get = function(path, type, options) {
|
|
|
1927
1934
|
|
|
1928
1935
|
if (schema != null && options.getters !== false) {
|
|
1929
1936
|
obj = schema.applyGetters(obj, this);
|
|
1930
|
-
} else if (this.$__schema.nested
|
|
1937
|
+
} else if (hasOwnProperty(this.$__schema.nested, path) && options.virtuals) {
|
|
1931
1938
|
// Might need to apply virtuals if this is a nested path
|
|
1932
1939
|
return applyVirtuals(this, utils.clone(obj) || {}, { path: path });
|
|
1933
1940
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const MongooseError = require('../../error/mongooseError');
|
|
3
4
|
const hasDollarKeys = require('./hasDollarKeys');
|
|
4
5
|
const { trustedSymbol } = require('./trusted');
|
|
5
6
|
|
|
@@ -17,12 +18,14 @@ module.exports = function sanitizeFilter(filter) {
|
|
|
17
18
|
const filterKeys = Object.keys(filter);
|
|
18
19
|
for (const key of filterKeys) {
|
|
19
20
|
const value = filter[key];
|
|
20
|
-
if (value
|
|
21
|
+
if (value && value[trustedSymbol]) {
|
|
21
22
|
continue;
|
|
22
23
|
}
|
|
23
|
-
if (key === '$and' || key === '$or') {
|
|
24
|
+
if (key === '$and' || key === '$or' || key === '$nor') {
|
|
24
25
|
sanitizeFilter(value);
|
|
25
26
|
continue;
|
|
27
|
+
} else if (key === '$jsonSchema' || key === '$where' || key === '$expr' || key === '$text') {
|
|
28
|
+
throw new MongooseError(key + ' is not allowed with sanitizeFilter');
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
if (hasDollarKeys(value)) {
|
|
@@ -5,7 +5,7 @@ const trustedSymbol = Symbol('mongoose#trustedSymbol');
|
|
|
5
5
|
exports.trustedSymbol = trustedSymbol;
|
|
6
6
|
|
|
7
7
|
exports.trusted = function trusted(obj) {
|
|
8
|
-
if (obj == null || typeof obj !== 'object') {
|
|
8
|
+
if (obj == null || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
|
9
9
|
return obj;
|
|
10
10
|
}
|
|
11
11
|
obj[trustedSymbol] = true;
|
package/lib/schema.js
CHANGED
|
@@ -955,7 +955,7 @@ reserved.collection = 1;
|
|
|
955
955
|
|
|
956
956
|
Schema.prototype.path = function(path, obj) {
|
|
957
957
|
if (obj === undefined) {
|
|
958
|
-
if (this.paths
|
|
958
|
+
if (Object.prototype.hasOwnProperty.call(this.paths, path)) {
|
|
959
959
|
return this.paths[path];
|
|
960
960
|
}
|
|
961
961
|
// Convert to '.$' to check subpaths re: gh-6405
|
|
@@ -983,9 +983,15 @@ Schema.prototype.path = function(path, obj) {
|
|
|
983
983
|
: undefined;
|
|
984
984
|
}
|
|
985
985
|
|
|
986
|
+
const subpaths = path.indexOf('.') === -1 ? [path] : path.split('.');
|
|
987
|
+
const last = subpaths.pop();
|
|
988
|
+
if (utils.specialProperties.has(last)) {
|
|
989
|
+
throw new Error('Cannot set special property `' + last + '` on a schema');
|
|
990
|
+
}
|
|
991
|
+
|
|
986
992
|
// some path names conflict with document methods
|
|
987
|
-
const firstPieceOfPath =
|
|
988
|
-
if (reserved
|
|
993
|
+
const firstPieceOfPath = subpaths.length === 0 ? last : subpaths[0];
|
|
994
|
+
if (Object.prototype.hasOwnProperty.call(reserved, firstPieceOfPath) && !this.options.supressReservedKeysWarning) {
|
|
989
995
|
const errorMessage = `\`${firstPieceOfPath}\` is a reserved schema pathname and may break some functionality. ` +
|
|
990
996
|
'You are allowed to use it, but use at your own risk. ' +
|
|
991
997
|
'To disable this warning pass `supressReservedKeysWarning` as a schema option.';
|
|
@@ -998,8 +1004,6 @@ Schema.prototype.path = function(path, obj) {
|
|
|
998
1004
|
}
|
|
999
1005
|
|
|
1000
1006
|
// update the tree
|
|
1001
|
-
const subpaths = path.split(/\./);
|
|
1002
|
-
const last = subpaths.pop();
|
|
1003
1007
|
let branch = this.tree;
|
|
1004
1008
|
let fullPath = '';
|
|
1005
1009
|
|
|
@@ -2589,7 +2593,7 @@ Schema.prototype._getPathType = function(path) {
|
|
|
2589
2593
|
};
|
|
2590
2594
|
}
|
|
2591
2595
|
return { schema: foundschema, pathType: 'real' };
|
|
2592
|
-
} else if (p === parts.length && schema.nested
|
|
2596
|
+
} else if (p === parts.length && Object.prototype.hasOwnProperty.call(schema.nested, trypath)) {
|
|
2593
2597
|
return { schema: schema, pathType: 'nested' };
|
|
2594
2598
|
}
|
|
2595
2599
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
|
|
5
5
|
const stdin = fs.readFileSync(0).toString('utf8');
|
|
6
|
-
const maxInstantiations = isNaN(process.argv[2]) ?
|
|
6
|
+
const maxInstantiations = isNaN(process.argv[2]) ? 110000 : parseInt(process.argv[2], 10);
|
|
7
7
|
|
|
8
8
|
console.log(stdin);
|
|
9
9
|
|
package/types/expressions.d.ts
CHANGED
|
@@ -1150,6 +1150,21 @@ declare module 'mongoose' {
|
|
|
1150
1150
|
$first: Expression;
|
|
1151
1151
|
}
|
|
1152
1152
|
|
|
1153
|
+
export interface FirstN {
|
|
1154
|
+
/**
|
|
1155
|
+
* $firstN can be used as an aggregation accumulator or array operator.
|
|
1156
|
+
* As an aggregation accumulator, it returns an aggregation of the first n elements within a group.
|
|
1157
|
+
* As an array operator, it returns the specified number of elements from the beginning of an array.
|
|
1158
|
+
*
|
|
1159
|
+
* @version 5.2
|
|
1160
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#mongodb-expression-exp.-first
|
|
1161
|
+
*/
|
|
1162
|
+
$firstN: {
|
|
1163
|
+
input: Expression
|
|
1164
|
+
n: Expression,
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1153
1168
|
export interface In {
|
|
1154
1169
|
/**
|
|
1155
1170
|
* Returns a boolean indicating whether a specified value is in an array.
|
|
@@ -1190,6 +1205,21 @@ declare module 'mongoose' {
|
|
|
1190
1205
|
$last: Expression;
|
|
1191
1206
|
}
|
|
1192
1207
|
|
|
1208
|
+
export interface LastN {
|
|
1209
|
+
/**
|
|
1210
|
+
* $lastN can be used as an aggregation accumulator or array operator.
|
|
1211
|
+
* As an aggregation accumulator, it an aggregation of the last n elements within a group.
|
|
1212
|
+
* As an array operator, it returns the specified number of elements from the end of an array.
|
|
1213
|
+
*
|
|
1214
|
+
* @version 5.2
|
|
1215
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#mongodb-group-grp.-lastN
|
|
1216
|
+
*/
|
|
1217
|
+
$lastN: {
|
|
1218
|
+
input: Expression
|
|
1219
|
+
n: Expression,
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1193
1223
|
export interface LinearFill {
|
|
1194
1224
|
/**
|
|
1195
1225
|
* Fills null and missing fields in a window using linear interpolation based on surrounding field values.
|
|
@@ -2000,6 +2030,34 @@ declare module 'mongoose' {
|
|
|
2000
2030
|
$avg: Expression;
|
|
2001
2031
|
}
|
|
2002
2032
|
|
|
2033
|
+
export interface Bottom {
|
|
2034
|
+
/**
|
|
2035
|
+
* Returns the bottom element within a group according to the specified sort order.
|
|
2036
|
+
*
|
|
2037
|
+
* @version 5.2
|
|
2038
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/#mongodb-group-grp.-bottom
|
|
2039
|
+
*/
|
|
2040
|
+
$bottom: {
|
|
2041
|
+
sortBy: AnyObject,
|
|
2042
|
+
output: Expression
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
export interface BottomN {
|
|
2047
|
+
/**
|
|
2048
|
+
* Returns an aggregation of the bottom n elements within a group, according to the specified sort order.
|
|
2049
|
+
* If the group contains fewer than n elements, $bottomN returns all elements in the group.
|
|
2050
|
+
*
|
|
2051
|
+
* @version 5.2
|
|
2052
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/#mongodb-group-grp.-bottomN
|
|
2053
|
+
*/
|
|
2054
|
+
$bottomN: {
|
|
2055
|
+
n: Expression,
|
|
2056
|
+
sortBy: AnyObject,
|
|
2057
|
+
output: Expression
|
|
2058
|
+
};
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2003
2061
|
export interface Count {
|
|
2004
2062
|
/**
|
|
2005
2063
|
* Returns the number of documents in a group.
|
|
@@ -2158,6 +2216,20 @@ declare module 'mongoose' {
|
|
|
2158
2216
|
$max: Expression | Expression[];
|
|
2159
2217
|
}
|
|
2160
2218
|
|
|
2219
|
+
export interface MaxN {
|
|
2220
|
+
/**
|
|
2221
|
+
* Returns an aggregation of the maxmimum value n elements within a group.
|
|
2222
|
+
* If the group contains fewer than n elements, $maxN returns all elements in the group.
|
|
2223
|
+
*
|
|
2224
|
+
* @version 5.2
|
|
2225
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/#mongodb-group-grp.-maxN
|
|
2226
|
+
*/
|
|
2227
|
+
$maxN: {
|
|
2228
|
+
input: Expression
|
|
2229
|
+
n: Expression,
|
|
2230
|
+
};
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2161
2233
|
export interface Min {
|
|
2162
2234
|
/**
|
|
2163
2235
|
* Returns the minimum value. $min compares both value and type, using the specified BSON comparison order for
|
|
@@ -2169,6 +2241,20 @@ declare module 'mongoose' {
|
|
|
2169
2241
|
$min: Expression | Expression[];
|
|
2170
2242
|
}
|
|
2171
2243
|
|
|
2244
|
+
export interface MinN {
|
|
2245
|
+
/**
|
|
2246
|
+
* Returns an aggregation of the minimum value n elements within a group.
|
|
2247
|
+
* If the group contains fewer than n elements, $minN returns all elements in the group.
|
|
2248
|
+
*
|
|
2249
|
+
* @version 5.2
|
|
2250
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/#mongodb-group-grp.-minN
|
|
2251
|
+
*/
|
|
2252
|
+
$minN: {
|
|
2253
|
+
input: Expression
|
|
2254
|
+
n: Expression,
|
|
2255
|
+
};
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2172
2258
|
export interface Push {
|
|
2173
2259
|
/**
|
|
2174
2260
|
* Returns an array of all values that result from applying an expression to documents.
|
|
@@ -2605,6 +2691,8 @@ declare module 'mongoose' {
|
|
|
2605
2691
|
export type ArrayExpressionOperatorReturningArray =
|
|
2606
2692
|
Expression.ConcatArrays |
|
|
2607
2693
|
Expression.Filter |
|
|
2694
|
+
Expression.FirstN |
|
|
2695
|
+
Expression.LastN |
|
|
2608
2696
|
Expression.Map |
|
|
2609
2697
|
Expression.ObjectToArray |
|
|
2610
2698
|
Expression.Range |
|
|
@@ -2763,12 +2851,16 @@ declare module 'mongoose' {
|
|
|
2763
2851
|
Expression.DocumentNumber |
|
|
2764
2852
|
Expression.ExpMovingAvg |
|
|
2765
2853
|
Expression.First |
|
|
2854
|
+
Expression.FirstN |
|
|
2766
2855
|
Expression.Integral |
|
|
2767
2856
|
Expression.Last |
|
|
2857
|
+
Expression.LastN |
|
|
2768
2858
|
Expression.LinearFill |
|
|
2769
2859
|
Expression.Locf |
|
|
2770
2860
|
Expression.Max |
|
|
2861
|
+
Expression.MaxN |
|
|
2771
2862
|
Expression.Min |
|
|
2863
|
+
Expression.MinN |
|
|
2772
2864
|
Expression.Push |
|
|
2773
2865
|
Expression.Rank |
|
|
2774
2866
|
Expression.Shift |
|
|
@@ -2783,6 +2875,10 @@ declare module 'mongoose' {
|
|
|
2783
2875
|
|
|
2784
2876
|
export type WindowOperatorReturningArray =
|
|
2785
2877
|
Expression.AddToSet |
|
|
2878
|
+
Expression.FirstN |
|
|
2879
|
+
Expression.LastN |
|
|
2880
|
+
Expression.MaxN |
|
|
2881
|
+
Expression.MinN |
|
|
2786
2882
|
Expression.Push;
|
|
2787
2883
|
|
|
2788
2884
|
export type WindowOperatorReturningNumber =
|
|
@@ -2858,12 +2954,18 @@ declare module 'mongoose' {
|
|
|
2858
2954
|
Expression.Accumulator |
|
|
2859
2955
|
Expression.AddToSet |
|
|
2860
2956
|
Expression.Avg |
|
|
2957
|
+
Expression.Bottom |
|
|
2958
|
+
Expression.BottomN |
|
|
2861
2959
|
Expression.Count |
|
|
2862
2960
|
Expression.First |
|
|
2961
|
+
Expression.FirstN |
|
|
2863
2962
|
Expression.Last |
|
|
2963
|
+
Expression.LastN |
|
|
2864
2964
|
Expression.Max |
|
|
2965
|
+
Expression.MaxN |
|
|
2865
2966
|
Expression.MergeObjects |
|
|
2866
2967
|
Expression.Min |
|
|
2968
|
+
Expression.MinN |
|
|
2867
2969
|
Expression.Push |
|
|
2868
2970
|
Expression.StdDevPop |
|
|
2869
2971
|
Expression.StdDevSamp |
|