mongoose 6.13.9 → 6.13.11
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/deno.lock +61 -0
- package/dist/browser.umd.js +1 -1
- package/lib/document.js +10 -3
- package/lib/query.js +15 -5
- package/lib/schema.js +10 -6
- package/package.json +1 -1
- package/.claude/settings.local.json +0 -7
- package/startmdb.mjs +0 -19
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
|
}
|
package/lib/query.js
CHANGED
|
@@ -2639,9 +2639,11 @@ Query.prototype.findOne = function(conditions, projection, options, callback) {
|
|
|
2639
2639
|
|
|
2640
2640
|
Query.prototype._count = wrapThunk(function(callback) {
|
|
2641
2641
|
try {
|
|
2642
|
-
this.
|
|
2642
|
+
this._castConditions();
|
|
2643
2643
|
} catch (err) {
|
|
2644
|
-
|
|
2644
|
+
// `_castConditions()` reports cast errors on the query, but `sanitizeFilter`
|
|
2645
|
+
// throws for filters it refuses outright, like `$where`.
|
|
2646
|
+
return callback(err);
|
|
2645
2647
|
}
|
|
2646
2648
|
|
|
2647
2649
|
if (this.error()) {
|
|
@@ -2667,9 +2669,11 @@ Query.prototype._count = wrapThunk(function(callback) {
|
|
|
2667
2669
|
|
|
2668
2670
|
Query.prototype._countDocuments = wrapThunk(function(callback) {
|
|
2669
2671
|
try {
|
|
2670
|
-
this.
|
|
2672
|
+
this._castConditions();
|
|
2671
2673
|
} catch (err) {
|
|
2672
|
-
|
|
2674
|
+
// `_castConditions()` reports cast errors on the query, but `sanitizeFilter`
|
|
2675
|
+
// throws for filters it refuses outright, like `$where`.
|
|
2676
|
+
return callback(err);
|
|
2673
2677
|
}
|
|
2674
2678
|
|
|
2675
2679
|
if (this.error()) {
|
|
@@ -5485,11 +5489,17 @@ Query.prototype.cursor = function cursor(opts) {
|
|
|
5485
5489
|
|
|
5486
5490
|
const options = this._optionsForExec();
|
|
5487
5491
|
try {
|
|
5488
|
-
this.
|
|
5492
|
+
this._castConditions();
|
|
5489
5493
|
} catch (err) {
|
|
5494
|
+
// `_castConditions()` reports cast errors on the query, but `sanitizeFilter`
|
|
5495
|
+
// throws for filters it refuses outright, like `$where`.
|
|
5490
5496
|
return (new QueryCursor(this, options))._markError(err);
|
|
5491
5497
|
}
|
|
5492
5498
|
|
|
5499
|
+
if (this.error()) {
|
|
5500
|
+
return (new QueryCursor(this, options))._markError(this.error());
|
|
5501
|
+
}
|
|
5502
|
+
|
|
5493
5503
|
return new QueryCursor(this, options);
|
|
5494
5504
|
};
|
|
5495
5505
|
|
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
package/startmdb.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { MongoMemoryReplSet } from 'mongodb-memory-server';
|
|
2
|
-
|
|
3
|
-
const replSet = await MongoMemoryReplSet.create({
|
|
4
|
-
binary: {
|
|
5
|
-
systemBinary: '/home/v/libs/mongodb-linux-x86_64-enterprise-ubuntu2404-8.2.0/bin/mongod'
|
|
6
|
-
},
|
|
7
|
-
instanceOpts: [
|
|
8
|
-
{
|
|
9
|
-
port: 27017
|
|
10
|
-
}
|
|
11
|
-
],
|
|
12
|
-
replSet: {
|
|
13
|
-
storageEngine: 'inMemory',
|
|
14
|
-
count: 1
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const uri = replSet.getUri();
|
|
19
|
-
console.log(uri);
|