mongoose 6.2.7 → 6.2.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/.eslintrc.json +35 -26
- package/CHANGELOG.md +27 -0
- package/dist/browser.umd.js +71 -71
- package/lib/aggregate.js +36 -36
- package/lib/browser.js +4 -4
- package/lib/browserDocument.js +1 -0
- package/lib/connection.js +21 -21
- package/lib/cursor/AggregationCursor.js +2 -3
- package/lib/cursor/QueryCursor.js +3 -3
- package/lib/document.js +75 -47
- package/lib/error/index.js +2 -2
- package/lib/helpers/document/handleSpreadDoc.js +19 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/query/castFilterPath.js +0 -1
- package/lib/index.js +24 -26
- package/lib/model.js +141 -136
- package/lib/options/SchemaArrayOptions.js +2 -2
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDateOptions.js +9 -2
- package/lib/options/SchemaDocumentArrayOptions.js +3 -3
- package/lib/options/SchemaMapOptions.js +2 -2
- package/lib/options/SchemaNumberOptions.js +3 -3
- package/lib/options/SchemaObjectIdOptions.js +2 -2
- package/lib/options/SchemaStringOptions.js +1 -1
- package/lib/options/SchemaSubdocumentOptions.js +2 -2
- package/lib/options/SchemaTypeOptions.js +3 -3
- package/lib/query.js +253 -225
- package/lib/schema/SubdocumentPath.js +6 -3
- package/lib/schema/array.js +3 -2
- package/lib/schema/boolean.js +4 -4
- package/lib/schema/buffer.js +3 -3
- package/lib/schema/date.js +7 -7
- package/lib/schema/decimal128.js +2 -2
- package/lib/schema/documentarray.js +17 -10
- package/lib/schema/mixed.js +2 -2
- package/lib/schema/number.js +6 -6
- package/lib/schema/objectid.js +4 -4
- package/lib/schema/string.js +14 -14
- package/lib/schema.js +28 -28
- package/lib/schematype.js +78 -68
- package/lib/types/ArraySubdocument.js +1 -1
- package/lib/types/DocumentArray/methods/index.js +2 -2
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +14 -12
- package/lib/types/buffer.js +1 -1
- package/lib/types/decimal128.js +1 -1
- package/lib/types/objectid.js +1 -1
- package/lib/types/subdocument.js +2 -2
- package/lib/virtualtype.js +4 -3
- package/package.json +18 -17
- package/tools/repl.js +8 -8
- package/tools/sharded.js +3 -3
- package/types/connection.d.ts +116 -116
- package/types/document.d.ts +3 -0
- package/types/error.d.ts +2 -2
- package/types/index.d.ts +75 -67
- package/types/pipelinestage.d.ts +194 -194
- package/types/schemaoptions.d.ts +2 -2
|
@@ -100,7 +100,7 @@ const methods = {
|
|
|
100
100
|
/**
|
|
101
101
|
* Atomically shifts the array at most one time per document `save()`.
|
|
102
102
|
*
|
|
103
|
-
* ####
|
|
103
|
+
* #### Note:
|
|
104
104
|
*
|
|
105
105
|
* _Calling this multiple times on an array before saving sends the same command as calling it once._
|
|
106
106
|
* _This update is implemented using the MongoDB [$pop](https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop) method which enforces this restriction._
|
|
@@ -365,7 +365,7 @@ const methods = {
|
|
|
365
365
|
/**
|
|
366
366
|
* Adds values to the array if not already present.
|
|
367
367
|
*
|
|
368
|
-
* ####Example:
|
|
368
|
+
* #### Example:
|
|
369
369
|
*
|
|
370
370
|
* console.log(doc.array) // [2,3,4]
|
|
371
371
|
* const added = doc.array.addToSet(4,5);
|
|
@@ -445,6 +445,7 @@ const methods = {
|
|
|
445
445
|
* Return whether or not the `obj` is included in the array.
|
|
446
446
|
*
|
|
447
447
|
* @param {Object} obj the item to check
|
|
448
|
+
* @param {Number} fromIndex
|
|
448
449
|
* @return {Boolean}
|
|
449
450
|
* @api public
|
|
450
451
|
* @method includes
|
|
@@ -460,6 +461,7 @@ const methods = {
|
|
|
460
461
|
* Return the index of `obj` or `-1` if not found.
|
|
461
462
|
*
|
|
462
463
|
* @param {Object} obj the item to look for
|
|
464
|
+
* @param {Number} fromIndex
|
|
463
465
|
* @return {Number}
|
|
464
466
|
* @api public
|
|
465
467
|
* @method indexOf
|
|
@@ -496,7 +498,7 @@ const methods = {
|
|
|
496
498
|
/**
|
|
497
499
|
* Pushes items to the array non-atomically.
|
|
498
500
|
*
|
|
499
|
-
* ####
|
|
501
|
+
* #### Note:
|
|
500
502
|
*
|
|
501
503
|
* _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
|
|
502
504
|
*
|
|
@@ -517,7 +519,7 @@ const methods = {
|
|
|
517
519
|
/**
|
|
518
520
|
* Wraps [`Array#pop`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/pop) with proper change tracking.
|
|
519
521
|
*
|
|
520
|
-
* ####Note:
|
|
522
|
+
* #### Note:
|
|
521
523
|
*
|
|
522
524
|
* _marks the entire array as modified which will pass the entire thing to $set potentially overwriting any changes that happen between when you retrieved the object and when you save it._
|
|
523
525
|
*
|
|
@@ -539,7 +541,7 @@ const methods = {
|
|
|
539
541
|
* the provided value to an embedded document and comparing using
|
|
540
542
|
* [the `Document.equals()` function.](/docs/api.html#document_Document-equals)
|
|
541
543
|
*
|
|
542
|
-
* ####Examples:
|
|
544
|
+
* #### Examples:
|
|
543
545
|
*
|
|
544
546
|
* doc.array.pull(ObjectId)
|
|
545
547
|
* doc.array.pull({ _id: 'someId' })
|
|
@@ -609,7 +611,7 @@ const methods = {
|
|
|
609
611
|
/**
|
|
610
612
|
* Wraps [`Array#push`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push) with proper change tracking.
|
|
611
613
|
*
|
|
612
|
-
* ####Example:
|
|
614
|
+
* #### Example:
|
|
613
615
|
*
|
|
614
616
|
* const schema = Schema({ nums: [Number] });
|
|
615
617
|
* const Model = mongoose.model('Test', schema);
|
|
@@ -704,7 +706,7 @@ const methods = {
|
|
|
704
706
|
/**
|
|
705
707
|
* Sets the casted `val` at index `i` and marks the array modified.
|
|
706
708
|
*
|
|
707
|
-
* ####Example:
|
|
709
|
+
* #### Example:
|
|
708
710
|
*
|
|
709
711
|
* // given documents based on the following
|
|
710
712
|
* const Doc = mongoose.model('Doc', new Schema({ array: [Number] }));
|
|
@@ -743,14 +745,14 @@ const methods = {
|
|
|
743
745
|
/**
|
|
744
746
|
* Wraps [`Array#shift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking.
|
|
745
747
|
*
|
|
746
|
-
* ####Example:
|
|
748
|
+
* #### Example:
|
|
747
749
|
*
|
|
748
750
|
* doc.array = [2,3];
|
|
749
751
|
* const res = doc.array.shift();
|
|
750
752
|
* console.log(res) // 2
|
|
751
753
|
* console.log(doc.array) // [3]
|
|
752
754
|
*
|
|
753
|
-
* ####Note:
|
|
755
|
+
* #### Note:
|
|
754
756
|
*
|
|
755
757
|
* _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
|
|
756
758
|
*
|
|
@@ -770,7 +772,7 @@ const methods = {
|
|
|
770
772
|
/**
|
|
771
773
|
* Wraps [`Array#sort`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort) with proper change tracking.
|
|
772
774
|
*
|
|
773
|
-
* ####
|
|
775
|
+
* #### Note:
|
|
774
776
|
*
|
|
775
777
|
* _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
|
|
776
778
|
*
|
|
@@ -790,7 +792,7 @@ const methods = {
|
|
|
790
792
|
/**
|
|
791
793
|
* Wraps [`Array#splice`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice) with proper change tracking and casting.
|
|
792
794
|
*
|
|
793
|
-
* ####Note:
|
|
795
|
+
* #### Note:
|
|
794
796
|
*
|
|
795
797
|
* _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
|
|
796
798
|
*
|
|
@@ -867,7 +869,7 @@ const methods = {
|
|
|
867
869
|
/**
|
|
868
870
|
* Wraps [`Array#unshift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking.
|
|
869
871
|
*
|
|
870
|
-
* ####Note:
|
|
872
|
+
* #### Note:
|
|
871
873
|
*
|
|
872
874
|
* _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwriting any changes that happen between when you retrieved the object and when you save it._
|
|
873
875
|
*
|
package/lib/types/buffer.js
CHANGED
|
@@ -113,7 +113,7 @@ MongooseBuffer.mixin = {
|
|
|
113
113
|
/**
|
|
114
114
|
* Copies the buffer.
|
|
115
115
|
*
|
|
116
|
-
* ####Note:
|
|
116
|
+
* #### Note:
|
|
117
117
|
*
|
|
118
118
|
* `Buffer#copy` does not mark `target` as modified so you must copy from a `MongooseBuffer` for it to work as expected. This is a work around since `copy` modifies the target, not this.
|
|
119
119
|
*
|
package/lib/types/decimal128.js
CHANGED
package/lib/types/objectid.js
CHANGED
package/lib/types/subdocument.js
CHANGED
|
@@ -58,7 +58,7 @@ Subdocument.prototype.toBSON = function() {
|
|
|
58
58
|
/**
|
|
59
59
|
* Used as a stub for middleware
|
|
60
60
|
*
|
|
61
|
-
* ####
|
|
61
|
+
* #### Note:
|
|
62
62
|
*
|
|
63
63
|
* _This is a no-op. Does not actually save the doc to the db._
|
|
64
64
|
*
|
|
@@ -116,7 +116,7 @@ Subdocument.prototype.$__pathRelativeToParent = function(p) {
|
|
|
116
116
|
/**
|
|
117
117
|
* Used as a stub for middleware
|
|
118
118
|
*
|
|
119
|
-
* ####
|
|
119
|
+
* #### Note:
|
|
120
120
|
*
|
|
121
121
|
* _This is a no-op. Does not actually save the doc to the db._
|
|
122
122
|
*
|
package/lib/virtualtype.js
CHANGED
|
@@ -7,7 +7,7 @@ const utils = require('./utils');
|
|
|
7
7
|
*
|
|
8
8
|
* This is what mongoose uses to define virtual attributes via `Schema.prototype.virtual`.
|
|
9
9
|
*
|
|
10
|
-
* ####Example:
|
|
10
|
+
* #### Example:
|
|
11
11
|
*
|
|
12
12
|
* const fullname = schema.virtual('fullname');
|
|
13
13
|
* fullname instanceof mongoose.VirtualType // true
|
|
@@ -24,6 +24,7 @@ const utils = require('./utils');
|
|
|
24
24
|
* @param {Number} [options.skip=null] add a default `skip` to the `populate()` query
|
|
25
25
|
* @param {Number} [options.perDocumentLimit=null] For legacy reasons, `limit` with `populate()` may give incorrect results because it only executes a single query for every document being populated. If you set `perDocumentLimit`, Mongoose will ensure correct `limit` per document by executing a separate query for each document to `populate()`. For example, `.find().populate({ path: 'test', perDocumentLimit: 2 })` will execute 2 additional queries if `.find()` returns 2 documents.
|
|
26
26
|
* @param {Object} [options.options=null] Additional options like `limit` and `lean`.
|
|
27
|
+
* @param {string} name
|
|
27
28
|
* @api public
|
|
28
29
|
*/
|
|
29
30
|
|
|
@@ -77,7 +78,7 @@ VirtualType.prototype.clone = function() {
|
|
|
77
78
|
* - `virtual`: the virtual object you called `.get()` on
|
|
78
79
|
* - `doc`: the document this virtual is attached to. Equivalent to `this`.
|
|
79
80
|
*
|
|
80
|
-
* ####Example:
|
|
81
|
+
* #### Example:
|
|
81
82
|
*
|
|
82
83
|
* const virtual = schema.virtual('fullname');
|
|
83
84
|
* virtual.get(function(value, virtual, doc) {
|
|
@@ -103,7 +104,7 @@ VirtualType.prototype.get = function(fn) {
|
|
|
103
104
|
* - `virtual`: the virtual object you're calling `.set()` on
|
|
104
105
|
* - `doc`: the document this virtual is attached to. Equivalent to `this`.
|
|
105
106
|
*
|
|
106
|
-
* ####Example:
|
|
107
|
+
* #### Example:
|
|
107
108
|
*
|
|
108
109
|
* const virtual = schema.virtual('fullname');
|
|
109
110
|
* virtual.set(function(value, virtual, doc) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.2.
|
|
4
|
+
"version": "6.2.10",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"bson": "^4.2.2",
|
|
23
|
-
"kareem": "2.3.
|
|
23
|
+
"kareem": "2.3.5",
|
|
24
24
|
"mongodb": "4.3.1",
|
|
25
25
|
"mpath": "0.8.4",
|
|
26
26
|
"mquery": "4.0.2",
|
|
@@ -28,33 +28,34 @@
|
|
|
28
28
|
"sift": "16.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "7.17.
|
|
31
|
+
"@babel/core": "7.17.8",
|
|
32
32
|
"@babel/preset-env": "7.16.11",
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
34
|
-
"@typescript-eslint/parser": "5.
|
|
35
|
-
"acquit": "1.
|
|
36
|
-
"acquit-ignore": "0.2.
|
|
37
|
-
"acquit-require": "0.1.
|
|
38
|
-
"
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "5.17.0",
|
|
34
|
+
"@typescript-eslint/parser": "5.17.0",
|
|
35
|
+
"acquit": "1.2.1",
|
|
36
|
+
"acquit-ignore": "0.2.0",
|
|
37
|
+
"acquit-require": "0.1.1",
|
|
38
|
+
"axios": "0.26.1",
|
|
39
|
+
"babel-loader": "8.2.4",
|
|
39
40
|
"benchmark": "2.1.4",
|
|
40
41
|
"bluebird": "3.7.2",
|
|
41
42
|
"cheerio": "1.0.0-rc.10",
|
|
42
43
|
"dox": "0.3.1",
|
|
43
|
-
"eslint": "8.
|
|
44
|
+
"eslint": "8.12.0",
|
|
44
45
|
"eslint-plugin-mocha-no-only": "1.1.1",
|
|
45
|
-
"highlight.js": "
|
|
46
|
+
"highlight.js": "11.5.0",
|
|
46
47
|
"lodash.isequal": "4.5.0",
|
|
47
48
|
"lodash.isequalwith": "4.4.0",
|
|
48
|
-
"marked": "
|
|
49
|
-
"mocha": "9.2.
|
|
49
|
+
"marked": "4.0.12",
|
|
50
|
+
"mocha": "9.2.2",
|
|
50
51
|
"moment": "2.x",
|
|
51
52
|
"mongodb-memory-server": "^8.3.0",
|
|
52
53
|
"nyc": "^15.1.0",
|
|
53
54
|
"pug": "3.0.2",
|
|
54
55
|
"q": "1.5.1",
|
|
55
56
|
"serve-handler": "6.1.3",
|
|
56
|
-
"tsd": "0.
|
|
57
|
-
"typescript": "4.
|
|
57
|
+
"tsd": "0.20.0",
|
|
58
|
+
"typescript": "4.6.3",
|
|
58
59
|
"uuid": "8.3.2",
|
|
59
60
|
"webpack": "4.44.1"
|
|
60
61
|
},
|
|
@@ -69,7 +70,7 @@
|
|
|
69
70
|
"release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy",
|
|
70
71
|
"mongo": "node ./tools/repl.js",
|
|
71
72
|
"test": "mocha --exit ./test/*.test.js",
|
|
72
|
-
"test-tsd": "tsd",
|
|
73
|
+
"test-tsd": "node ./test/types/check-types-filename && tsd",
|
|
73
74
|
"tdd": "mocha ./test/*.test.js ./test/typescript/main.test.js --inspect --watch --recursive --watch-files ./**/*.js",
|
|
74
75
|
"test-coverage": "nyc --reporter=html --reporter=text npm test"
|
|
75
76
|
},
|
|
@@ -116,4 +117,4 @@
|
|
|
116
117
|
"target": "ES2017"
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
|
-
}
|
|
120
|
+
}
|
package/tools/repl.js
CHANGED
|
@@ -5,7 +5,7 @@ run().catch(error => {
|
|
|
5
5
|
process.exit(-1);
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
async function run
|
|
8
|
+
async function run() {
|
|
9
9
|
const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet;
|
|
10
10
|
|
|
11
11
|
// Create new instance
|
|
@@ -15,20 +15,20 @@ async function run () {
|
|
|
15
15
|
},
|
|
16
16
|
instanceOpts: [
|
|
17
17
|
// Set the expiry job in MongoDB to run every second
|
|
18
|
-
{
|
|
18
|
+
{
|
|
19
19
|
port: 27017,
|
|
20
|
-
args: [
|
|
20
|
+
args: ['--setParameter', 'ttlMonitorSleepSecs=1'] }
|
|
21
21
|
],
|
|
22
22
|
dbName: 'mongoose_test',
|
|
23
23
|
replSet: {
|
|
24
|
-
name:
|
|
24
|
+
name: 'rs0',
|
|
25
25
|
count: 2,
|
|
26
|
-
storageEngine:
|
|
27
|
-
}
|
|
26
|
+
storageEngine: 'wiredTiger'
|
|
27
|
+
}
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
await replSet.start();
|
|
31
31
|
await replSet.waitUntilRunning();
|
|
32
|
-
console.log(
|
|
33
|
-
console.log(replSet.getUri(
|
|
32
|
+
console.log('MongoDB-ReplicaSet is now running.');
|
|
33
|
+
console.log(replSet.getUri('mongoose_test'));
|
|
34
34
|
}
|
package/tools/sharded.js
CHANGED
|
@@ -6,7 +6,7 @@ run().catch(error => {
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
async function run
|
|
9
|
+
async function run() {
|
|
10
10
|
const Sharded = require('mongodb-topology-manager').Sharded;
|
|
11
11
|
|
|
12
12
|
// Create new instance
|
|
@@ -17,13 +17,13 @@ async function run () {
|
|
|
17
17
|
|
|
18
18
|
await topology.addShard([{
|
|
19
19
|
options: {
|
|
20
|
-
bind_ip: 'localhost', port: 31000, dbpath:
|
|
20
|
+
bind_ip: 'localhost', port: 31000, dbpath: '/data/db/31000', shardsvr: null
|
|
21
21
|
}
|
|
22
22
|
}], { replSet: 'rs1' });
|
|
23
23
|
|
|
24
24
|
await topology.addConfigurationServers([{
|
|
25
25
|
options: {
|
|
26
|
-
bind_ip: 'localhost', port: 35000, dbpath:
|
|
26
|
+
bind_ip: 'localhost', port: 35000, dbpath: '/data/db/35000'
|
|
27
27
|
}
|
|
28
28
|
}], { replSet: 'rs0' });
|
|
29
29
|
|