mongoose 6.4.3 → 6.4.6
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/aggregate.js +3 -2
- package/lib/connection.js +9 -9
- package/lib/cursor/AggregationCursor.js +3 -2
- package/lib/cursor/QueryCursor.js +5 -4
- package/lib/document.js +44 -16
- package/lib/error/index.js +12 -12
- package/lib/error/messages.js +2 -2
- package/lib/helpers/query/castUpdate.js +4 -4
- package/lib/helpers/timestamps/setDocumentTimestamps.js +26 -0
- package/lib/helpers/timestamps/setupTimestamps.js +14 -18
- package/lib/helpers/topology/isAtlas.js +14 -9
- package/lib/index.js +6 -2
- package/lib/model.js +129 -170
- package/lib/options/SchemaArrayOptions.js +2 -2
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDateOptions.js +3 -3
- package/lib/options/SchemaDocumentArrayOptions.js +2 -2
- package/lib/options/SchemaMapOptions.js +1 -1
- package/lib/options/SchemaNumberOptions.js +4 -4
- package/lib/options/SchemaObjectIdOptions.js +2 -2
- package/lib/options/SchemaStringOptions.js +8 -8
- package/lib/options/SchemaSubdocumentOptions.js +1 -1
- package/lib/options/SchemaTypeOptions.js +14 -14
- package/lib/options/VirtualOptions.js +11 -11
- package/lib/query.js +82 -73
- package/lib/schema/SubdocumentPath.js +10 -6
- package/lib/schema/array.js +3 -3
- package/lib/schema/boolean.js +5 -5
- package/lib/schema/buffer.js +2 -2
- package/lib/schema/date.js +2 -2
- package/lib/schema/decimal128.js +2 -2
- package/lib/schema/documentarray.js +12 -8
- package/lib/schema/mixed.js +2 -2
- package/lib/schema/number.js +2 -2
- package/lib/schema/objectid.js +2 -2
- package/lib/schema/string.js +2 -2
- package/lib/schema.js +76 -34
- package/lib/schematype.js +7 -9
- package/lib/types/DocumentArray/methods/index.js +1 -1
- package/lib/types/buffer.js +8 -4
- package/lib/types/decimal128.js +1 -1
- package/lib/types/map.js +1 -1
- package/lib/types/objectid.js +1 -1
- package/lib/types/subdocument.js +1 -1
- package/lib/virtualtype.js +5 -5
- package/package.json +7 -7
- package/types/expressions.d.ts +5 -4
- package/types/index.d.ts +9 -7
- package/types/indexes.d.ts +2 -2
- package/types/inferschematype.d.ts +26 -10
- package/types/models.d.ts +2 -1
- package/types/query.d.ts +6 -1
package/lib/query.js
CHANGED
|
@@ -170,7 +170,7 @@ Query.base = mquery.prototype;
|
|
|
170
170
|
* @default true
|
|
171
171
|
* @property use$geoWithin
|
|
172
172
|
* @memberOf Query
|
|
173
|
-
* @
|
|
173
|
+
* @static
|
|
174
174
|
* @api public
|
|
175
175
|
*/
|
|
176
176
|
|
|
@@ -179,7 +179,7 @@ Query.use$geoWithin = mquery.use$geoWithin;
|
|
|
179
179
|
/**
|
|
180
180
|
* Converts this query to a customized, reusable query constructor with all arguments and options retained.
|
|
181
181
|
*
|
|
182
|
-
* #### Example
|
|
182
|
+
* #### Example:
|
|
183
183
|
*
|
|
184
184
|
* // Create a query for adventure movies and read from the primary
|
|
185
185
|
* // node in the replica-set unless it is down, in which case we'll
|
|
@@ -309,7 +309,7 @@ Query.prototype.clone = function clone() {
|
|
|
309
309
|
/**
|
|
310
310
|
* Specifies a javascript function or expression to pass to MongoDBs query system.
|
|
311
311
|
*
|
|
312
|
-
* #### Example
|
|
312
|
+
* #### Example:
|
|
313
313
|
*
|
|
314
314
|
* query.$where('this.comments.length === 10 || this.name.length === 5')
|
|
315
315
|
*
|
|
@@ -337,7 +337,7 @@ Query.prototype.clone = function clone() {
|
|
|
337
337
|
/**
|
|
338
338
|
* Specifies a `path` for use with chaining.
|
|
339
339
|
*
|
|
340
|
-
* #### Example
|
|
340
|
+
* #### Example:
|
|
341
341
|
*
|
|
342
342
|
* // instead of writing:
|
|
343
343
|
* User.find({age: {$gte: 21, $lte: 65}}, callback);
|
|
@@ -367,7 +367,7 @@ Query.prototype.clone = function clone() {
|
|
|
367
367
|
/**
|
|
368
368
|
* Specifies a `$slice` projection for an array.
|
|
369
369
|
*
|
|
370
|
-
* #### Example
|
|
370
|
+
* #### Example:
|
|
371
371
|
*
|
|
372
372
|
* query.slice('comments', 5);
|
|
373
373
|
* query.slice('comments', -5);
|
|
@@ -445,7 +445,7 @@ Query.prototype._validateOp = function() {
|
|
|
445
445
|
/**
|
|
446
446
|
* Specifies the complementary comparison value for paths specified with `where()`
|
|
447
447
|
*
|
|
448
|
-
* #### Example
|
|
448
|
+
* #### Example:
|
|
449
449
|
*
|
|
450
450
|
* User.where('age').equals(49);
|
|
451
451
|
*
|
|
@@ -464,7 +464,7 @@ Query.prototype._validateOp = function() {
|
|
|
464
464
|
/**
|
|
465
465
|
* Specifies arguments for an `$or` condition.
|
|
466
466
|
*
|
|
467
|
-
* #### Example
|
|
467
|
+
* #### Example:
|
|
468
468
|
*
|
|
469
469
|
* query.or([{ color: 'red' }, { status: 'emergency' }]);
|
|
470
470
|
*
|
|
@@ -480,7 +480,7 @@ Query.prototype._validateOp = function() {
|
|
|
480
480
|
/**
|
|
481
481
|
* Specifies arguments for a `$nor` condition.
|
|
482
482
|
*
|
|
483
|
-
* #### Example
|
|
483
|
+
* #### Example:
|
|
484
484
|
*
|
|
485
485
|
* query.nor([{ color: 'green' }, { status: 'ok' }]);
|
|
486
486
|
*
|
|
@@ -496,7 +496,7 @@ Query.prototype._validateOp = function() {
|
|
|
496
496
|
/**
|
|
497
497
|
* Specifies arguments for a `$and` condition.
|
|
498
498
|
*
|
|
499
|
-
* #### Example
|
|
499
|
+
* #### Example:
|
|
500
500
|
*
|
|
501
501
|
* query.and([{ color: 'green' }, { status: 'ok' }])
|
|
502
502
|
*
|
|
@@ -514,7 +514,7 @@ Query.prototype._validateOp = function() {
|
|
|
514
514
|
*
|
|
515
515
|
* When called with one argument, the most recent path passed to `where()` is used.
|
|
516
516
|
*
|
|
517
|
-
* #### Example
|
|
517
|
+
* #### Example:
|
|
518
518
|
*
|
|
519
519
|
* Thing.find().where('age').gt(21);
|
|
520
520
|
*
|
|
@@ -639,7 +639,7 @@ Query.prototype._validateOp = function() {
|
|
|
639
639
|
*
|
|
640
640
|
* When called with one argument, the most recent path passed to `where()` is used.
|
|
641
641
|
*
|
|
642
|
-
* #### Example
|
|
642
|
+
* #### Example:
|
|
643
643
|
*
|
|
644
644
|
* const docs = await MyModel.where('tags').size(0).exec();
|
|
645
645
|
* assert(Array.isArray(docs));
|
|
@@ -686,7 +686,7 @@ Query.prototype._validateOp = function() {
|
|
|
686
686
|
* Specifies a `$mod` condition, filters documents for documents whose
|
|
687
687
|
* `path` property is a number that is equal to `remainder` modulo `divisor`.
|
|
688
688
|
*
|
|
689
|
-
* #### Example
|
|
689
|
+
* #### Example:
|
|
690
690
|
*
|
|
691
691
|
* // All find products whose inventory is odd
|
|
692
692
|
* Product.find().mod('inventory', [2, 1]);
|
|
@@ -732,7 +732,7 @@ Query.prototype.mod = function() {
|
|
|
732
732
|
/**
|
|
733
733
|
* Specifies an `$exists` condition
|
|
734
734
|
*
|
|
735
|
-
* #### Example
|
|
735
|
+
* #### Example:
|
|
736
736
|
*
|
|
737
737
|
* // { name: { $exists: true }}
|
|
738
738
|
* Thing.where('name').exists()
|
|
@@ -756,7 +756,7 @@ Query.prototype.mod = function() {
|
|
|
756
756
|
/**
|
|
757
757
|
* Specifies an `$elemMatch` condition
|
|
758
758
|
*
|
|
759
|
-
* #### Example
|
|
759
|
+
* #### Example:
|
|
760
760
|
*
|
|
761
761
|
* query.elemMatch('comment', { author: 'autobot', votes: {$gte: 5}})
|
|
762
762
|
*
|
|
@@ -785,7 +785,7 @@ Query.prototype.mod = function() {
|
|
|
785
785
|
/**
|
|
786
786
|
* Defines a `$within` or `$geoWithin` argument for geo-spatial queries.
|
|
787
787
|
*
|
|
788
|
-
* #### Example
|
|
788
|
+
* #### Example:
|
|
789
789
|
*
|
|
790
790
|
* query.where(path).within().box()
|
|
791
791
|
* query.where(path).within().circle()
|
|
@@ -824,11 +824,11 @@ Query.prototype.mod = function() {
|
|
|
824
824
|
/**
|
|
825
825
|
* Specifies the maximum number of documents the query will return.
|
|
826
826
|
*
|
|
827
|
-
* #### Example
|
|
827
|
+
* #### Example:
|
|
828
828
|
*
|
|
829
829
|
* query.limit(20);
|
|
830
830
|
*
|
|
831
|
-
* #### Note
|
|
831
|
+
* #### Note:
|
|
832
832
|
*
|
|
833
833
|
* Cannot be used with `distinct()`
|
|
834
834
|
*
|
|
@@ -857,11 +857,11 @@ Query.prototype.limit = function limit(v) {
|
|
|
857
857
|
/**
|
|
858
858
|
* Specifies the number of documents to skip.
|
|
859
859
|
*
|
|
860
|
-
* #### Example
|
|
860
|
+
* #### Example:
|
|
861
861
|
*
|
|
862
862
|
* query.skip(100).limit(20);
|
|
863
863
|
*
|
|
864
|
-
* #### Note
|
|
864
|
+
* #### Note:
|
|
865
865
|
*
|
|
866
866
|
* Cannot be used with `distinct()`
|
|
867
867
|
*
|
|
@@ -891,11 +891,11 @@ Query.prototype.skip = function skip(v) {
|
|
|
891
891
|
/**
|
|
892
892
|
* Specifies the maxScan option.
|
|
893
893
|
*
|
|
894
|
-
* #### Example
|
|
894
|
+
* #### Example:
|
|
895
895
|
*
|
|
896
896
|
* query.maxScan(100);
|
|
897
897
|
*
|
|
898
|
-
* #### Note
|
|
898
|
+
* #### Note:
|
|
899
899
|
*
|
|
900
900
|
* Cannot be used with `distinct()`
|
|
901
901
|
*
|
|
@@ -910,11 +910,11 @@ Query.prototype.skip = function skip(v) {
|
|
|
910
910
|
/**
|
|
911
911
|
* Specifies the batchSize option.
|
|
912
912
|
*
|
|
913
|
-
* #### Example
|
|
913
|
+
* #### Example:
|
|
914
914
|
*
|
|
915
915
|
* query.batchSize(100)
|
|
916
916
|
*
|
|
917
|
-
* #### Note
|
|
917
|
+
* #### Note:
|
|
918
918
|
*
|
|
919
919
|
* Cannot be used with `distinct()`
|
|
920
920
|
*
|
|
@@ -929,11 +929,11 @@ Query.prototype.skip = function skip(v) {
|
|
|
929
929
|
/**
|
|
930
930
|
* Specifies the `comment` option.
|
|
931
931
|
*
|
|
932
|
-
* #### Example
|
|
932
|
+
* #### Example:
|
|
933
933
|
*
|
|
934
934
|
* query.comment('login query')
|
|
935
935
|
*
|
|
936
|
-
* #### Note
|
|
936
|
+
* #### Note:
|
|
937
937
|
*
|
|
938
938
|
* Cannot be used with `distinct()`
|
|
939
939
|
*
|
|
@@ -948,13 +948,13 @@ Query.prototype.skip = function skip(v) {
|
|
|
948
948
|
/**
|
|
949
949
|
* Specifies this query as a `snapshot` query.
|
|
950
950
|
*
|
|
951
|
-
* #### Example
|
|
951
|
+
* #### Example:
|
|
952
952
|
*
|
|
953
953
|
* query.snapshot(); // true
|
|
954
954
|
* query.snapshot(true);
|
|
955
955
|
* query.snapshot(false);
|
|
956
956
|
*
|
|
957
|
-
* #### Note
|
|
957
|
+
* #### Note:
|
|
958
958
|
*
|
|
959
959
|
* Cannot be used with `distinct()`
|
|
960
960
|
*
|
|
@@ -969,11 +969,11 @@ Query.prototype.skip = function skip(v) {
|
|
|
969
969
|
/**
|
|
970
970
|
* Sets query hints.
|
|
971
971
|
*
|
|
972
|
-
* #### Example
|
|
972
|
+
* #### Example:
|
|
973
973
|
*
|
|
974
974
|
* query.hint({ indexA: 1, indexB: -1 });
|
|
975
975
|
*
|
|
976
|
-
* #### Note
|
|
976
|
+
* #### Note:
|
|
977
977
|
*
|
|
978
978
|
* Cannot be used with `distinct()`
|
|
979
979
|
*
|
|
@@ -1036,7 +1036,7 @@ Query.prototype.projection = function(arg) {
|
|
|
1036
1036
|
* either list the fields to include (which excludes all others), or list the fields
|
|
1037
1037
|
* to exclude (which implies all other fields are included). The [`_id` field is the only exception because MongoDB includes it by default](https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/#suppress-id-field).
|
|
1038
1038
|
*
|
|
1039
|
-
* #### Example
|
|
1039
|
+
* #### Example:
|
|
1040
1040
|
*
|
|
1041
1041
|
* // include a and b, exclude other fields
|
|
1042
1042
|
* query.select('a b');
|
|
@@ -1069,7 +1069,7 @@ Query.prototype.projection = function(arg) {
|
|
|
1069
1069
|
* @method select
|
|
1070
1070
|
* @memberOf Query
|
|
1071
1071
|
* @instance
|
|
1072
|
-
* @param {Object|String|
|
|
1072
|
+
* @param {Object|String|String[]} arg
|
|
1073
1073
|
* @return {Query} this
|
|
1074
1074
|
* @see SchemaType
|
|
1075
1075
|
* @api public
|
|
@@ -1847,7 +1847,7 @@ Query.prototype.setUpdate = function(val) {
|
|
|
1847
1847
|
* @method _fieldsForExec
|
|
1848
1848
|
* @return {Object}
|
|
1849
1849
|
* @api private
|
|
1850
|
-
* @
|
|
1850
|
+
* @memberOf Query
|
|
1851
1851
|
*/
|
|
1852
1852
|
|
|
1853
1853
|
Query.prototype._fieldsForExec = function() {
|
|
@@ -1859,8 +1859,9 @@ Query.prototype._fieldsForExec = function() {
|
|
|
1859
1859
|
* Return an update document with corrected `$set` operations.
|
|
1860
1860
|
*
|
|
1861
1861
|
* @method _updateForExec
|
|
1862
|
+
* @return {Object}
|
|
1862
1863
|
* @api private
|
|
1863
|
-
* @
|
|
1864
|
+
* @memberOf Query
|
|
1864
1865
|
*/
|
|
1865
1866
|
|
|
1866
1867
|
Query.prototype._updateForExec = function() {
|
|
@@ -1907,10 +1908,12 @@ Query.prototype._updateForExec = function() {
|
|
|
1907
1908
|
/**
|
|
1908
1909
|
* Makes sure _path is set.
|
|
1909
1910
|
*
|
|
1911
|
+
* This method is inherited by `mquery`
|
|
1912
|
+
*
|
|
1910
1913
|
* @method _ensurePath
|
|
1911
1914
|
* @param {String} method
|
|
1912
1915
|
* @api private
|
|
1913
|
-
* @
|
|
1916
|
+
* @memberOf Query
|
|
1914
1917
|
*/
|
|
1915
1918
|
|
|
1916
1919
|
/**
|
|
@@ -2291,7 +2294,7 @@ Query.prototype._find = wrapThunk(function(callback) {
|
|
|
2291
2294
|
* If there are too many documents in the result to fit in memory, use
|
|
2292
2295
|
* [`Query.prototype.cursor()`](api.html#query_Query-cursor)
|
|
2293
2296
|
*
|
|
2294
|
-
* #### Example
|
|
2297
|
+
* #### Example:
|
|
2295
2298
|
*
|
|
2296
2299
|
* // Using async/await
|
|
2297
2300
|
* const arr = await Movie.find({ year: { $gte: 1980, $lte: 1989 } });
|
|
@@ -2506,7 +2509,7 @@ Query.prototype._findOne = wrapThunk(function(callback) {
|
|
|
2506
2509
|
*
|
|
2507
2510
|
* - `findOne()`
|
|
2508
2511
|
*
|
|
2509
|
-
* #### Example
|
|
2512
|
+
* #### Example:
|
|
2510
2513
|
*
|
|
2511
2514
|
* const query = Kitten.where({ color: 'white' });
|
|
2512
2515
|
* query.findOne(function (err, kitten) {
|
|
@@ -2857,7 +2860,7 @@ Query.prototype.__distinct = wrapThunk(function __distinct(callback) {
|
|
|
2857
2860
|
*
|
|
2858
2861
|
* This function does not trigger any middleware.
|
|
2859
2862
|
*
|
|
2860
|
-
* #### Example
|
|
2863
|
+
* #### Example:
|
|
2861
2864
|
*
|
|
2862
2865
|
* distinct(field, conditions, callback)
|
|
2863
2866
|
* distinct(field, conditions)
|
|
@@ -2918,7 +2921,7 @@ Query.prototype.distinct = function(field, conditions, callback) {
|
|
|
2918
2921
|
* sort order of each path is ascending unless the path name is prefixed with `-`
|
|
2919
2922
|
* which will be treated as descending.
|
|
2920
2923
|
*
|
|
2921
|
-
* #### Example
|
|
2924
|
+
* #### Example:
|
|
2922
2925
|
*
|
|
2923
2926
|
* // sort by "field" ascending and "test" descending
|
|
2924
2927
|
* query.sort({ field: 'asc', test: -1 });
|
|
@@ -2926,7 +2929,7 @@ Query.prototype.distinct = function(field, conditions, callback) {
|
|
|
2926
2929
|
* // equivalent
|
|
2927
2930
|
* query.sort('field -test');
|
|
2928
2931
|
*
|
|
2929
|
-
* #### Note
|
|
2932
|
+
* #### Note:
|
|
2930
2933
|
*
|
|
2931
2934
|
* Cannot be used with `distinct()`
|
|
2932
2935
|
*
|
|
@@ -2951,7 +2954,7 @@ Query.prototype.sort = function(arg) {
|
|
|
2951
2954
|
*
|
|
2952
2955
|
* This function does not trigger any middleware
|
|
2953
2956
|
*
|
|
2954
|
-
* #### Example
|
|
2957
|
+
* #### Example:
|
|
2955
2958
|
*
|
|
2956
2959
|
* Character.remove({ name: /Stark/ }, callback);
|
|
2957
2960
|
*
|
|
@@ -2963,13 +2966,13 @@ Query.prototype.sort = function(arg) {
|
|
|
2963
2966
|
* - `deletedCount`: the number of documents deleted
|
|
2964
2967
|
* - `n`: the number of documents deleted. Equal to `deletedCount`.
|
|
2965
2968
|
*
|
|
2966
|
-
* #### Example
|
|
2969
|
+
* #### Example:
|
|
2967
2970
|
*
|
|
2968
2971
|
* const res = await Character.remove({ name: /Stark/ });
|
|
2969
2972
|
* // Number of docs deleted
|
|
2970
2973
|
* res.deletedCount;
|
|
2971
2974
|
*
|
|
2972
|
-
* #### Note
|
|
2975
|
+
* #### Note:
|
|
2973
2976
|
*
|
|
2974
2977
|
* Calling `remove()` creates a [Mongoose query](./queries.html), and a query
|
|
2975
2978
|
* does not execute until you either pass a callback, call [`Query#then()`](#query_Query-then),
|
|
@@ -3043,7 +3046,7 @@ Query.prototype._remove = wrapThunk(function(callback) {
|
|
|
3043
3046
|
*
|
|
3044
3047
|
* This function triggers `deleteOne` middleware.
|
|
3045
3048
|
*
|
|
3046
|
-
* #### Example
|
|
3049
|
+
* #### Example:
|
|
3047
3050
|
*
|
|
3048
3051
|
* await Character.deleteOne({ name: 'Eddard Stark' });
|
|
3049
3052
|
*
|
|
@@ -3058,7 +3061,7 @@ Query.prototype._remove = wrapThunk(function(callback) {
|
|
|
3058
3061
|
* - `deletedCount`: the number of documents deleted
|
|
3059
3062
|
* - `n`: the number of documents deleted. Equal to `deletedCount`.
|
|
3060
3063
|
*
|
|
3061
|
-
* #### Example
|
|
3064
|
+
* #### Example:
|
|
3062
3065
|
*
|
|
3063
3066
|
* const res = await Character.deleteOne({ name: 'Eddard Stark' });
|
|
3064
3067
|
* // `1` if MongoDB deleted a doc, `0` if no docs matched the filter `{ name: ... }`
|
|
@@ -3129,7 +3132,7 @@ Query.prototype._deleteOne = wrapThunk(function(callback) {
|
|
|
3129
3132
|
*
|
|
3130
3133
|
* This function triggers `deleteMany` middleware.
|
|
3131
3134
|
*
|
|
3132
|
-
* #### Example
|
|
3135
|
+
* #### Example:
|
|
3133
3136
|
*
|
|
3134
3137
|
* await Character.deleteMany({ name: /Stark/, age: { $gte: 18 } });
|
|
3135
3138
|
*
|
|
@@ -3144,7 +3147,7 @@ Query.prototype._deleteOne = wrapThunk(function(callback) {
|
|
|
3144
3147
|
* - `deletedCount`: the number of documents deleted
|
|
3145
3148
|
* - `n`: the number of documents deleted. Equal to `deletedCount`.
|
|
3146
3149
|
*
|
|
3147
|
-
* #### Example
|
|
3150
|
+
* #### Example:
|
|
3148
3151
|
*
|
|
3149
3152
|
* const res = await Character.deleteMany({ name: /Stark/, age: { $gte: 18 } });
|
|
3150
3153
|
* // `0` if no docs matched the filter, number of docs deleted otherwise
|
|
@@ -3296,7 +3299,7 @@ function prepareDiscriminatorCriteria(query) {
|
|
|
3296
3299
|
* // doc: the document before updates are applied if `new: false`, or after updates if `new = true`
|
|
3297
3300
|
* }
|
|
3298
3301
|
*
|
|
3299
|
-
* #### Examples
|
|
3302
|
+
* #### Examples:
|
|
3300
3303
|
*
|
|
3301
3304
|
* query.findOneAndUpdate(conditions, update, options, callback) // executes
|
|
3302
3305
|
* query.findOneAndUpdate(conditions, update, options) // returns Query
|
|
@@ -3438,7 +3441,7 @@ Query.prototype._findOneAndUpdate = wrapThunk(function(callback) {
|
|
|
3438
3441
|
* // doc: the document before updates are applied if `new: false`, or after updates if `new = true`
|
|
3439
3442
|
* }
|
|
3440
3443
|
*
|
|
3441
|
-
* #### Examples
|
|
3444
|
+
* #### Examples:
|
|
3442
3445
|
*
|
|
3443
3446
|
* A.where().findOneAndRemove(conditions, options, callback) // executes
|
|
3444
3447
|
* A.where().findOneAndRemove(conditions, options) // return Query
|
|
@@ -3525,7 +3528,7 @@ Query.prototype.findOneAndRemove = function(conditions, options, callback) {
|
|
|
3525
3528
|
* // doc: the document before updates are applied if `new: false`, or after updates if `new = true`
|
|
3526
3529
|
* }
|
|
3527
3530
|
*
|
|
3528
|
-
* #### Examples
|
|
3531
|
+
* #### Examples:
|
|
3529
3532
|
*
|
|
3530
3533
|
* A.where().findOneAndDelete(conditions, options, callback) // executes
|
|
3531
3534
|
* A.where().findOneAndDelete(conditions, options) // return Query
|
|
@@ -3644,7 +3647,7 @@ Query.prototype._findOneAndDelete = wrapThunk(function(callback) {
|
|
|
3644
3647
|
* // doc: the document before updates are applied if `new: false`, or after updates if `new = true`
|
|
3645
3648
|
* }
|
|
3646
3649
|
*
|
|
3647
|
-
* #### Examples
|
|
3650
|
+
* #### Examples:
|
|
3648
3651
|
*
|
|
3649
3652
|
* A.where().findOneAndReplace(filter, replacement, options, callback); // executes
|
|
3650
3653
|
* A.where().findOneAndReplace(filter, replacement, options); // return Query
|
|
@@ -3865,7 +3868,7 @@ function _getOption(query, option, def) {
|
|
|
3865
3868
|
/*!
|
|
3866
3869
|
* Override mquery.prototype._findAndModify to provide casting etc.
|
|
3867
3870
|
*
|
|
3868
|
-
* @param {String} type
|
|
3871
|
+
* @param {String} type either "remove" or "update"
|
|
3869
3872
|
* @param {Function} callback
|
|
3870
3873
|
* @api private
|
|
3871
3874
|
*/
|
|
@@ -4016,7 +4019,9 @@ Query.prototype._findAndModify = function(type, callback) {
|
|
|
4016
4019
|
*/
|
|
4017
4020
|
|
|
4018
4021
|
function _completeOneLean(schema, doc, path, res, opts, callback) {
|
|
4019
|
-
if (opts.lean && opts.lean.transform) {
|
|
4022
|
+
if (opts.lean && typeof opts.lean.transform === 'function') {
|
|
4023
|
+
opts.lean.transform(doc);
|
|
4024
|
+
|
|
4020
4025
|
for (let i = 0; i < schema.childSchemas.length; i++) {
|
|
4021
4026
|
const childPath = path ? path + '.' + schema.childSchemas[i].model.path : schema.childSchemas[i].model.path;
|
|
4022
4027
|
const _schema = schema.childSchemas[i].schema;
|
|
@@ -4050,7 +4055,11 @@ function _completeOneLean(schema, doc, path, res, opts, callback) {
|
|
|
4050
4055
|
*/
|
|
4051
4056
|
|
|
4052
4057
|
function _completeManyLean(schema, docs, path, opts, callback) {
|
|
4053
|
-
if (opts.lean && opts.lean.transform) {
|
|
4058
|
+
if (opts.lean && typeof opts.lean.transform === 'function') {
|
|
4059
|
+
for (const doc of docs) {
|
|
4060
|
+
opts.lean.transform(doc);
|
|
4061
|
+
}
|
|
4062
|
+
|
|
4054
4063
|
for (let i = 0; i < schema.childSchemas.length; i++) {
|
|
4055
4064
|
const childPath = path ? path + '.' + schema.childSchemas[i].model.path : schema.childSchemas[i].model.path;
|
|
4056
4065
|
const _schema = schema.childSchemas[i].schema;
|
|
@@ -4285,7 +4294,7 @@ Query.prototype._replaceOne = wrapThunk(function(callback) {
|
|
|
4285
4294
|
*
|
|
4286
4295
|
* - `update()`
|
|
4287
4296
|
*
|
|
4288
|
-
* #### Example
|
|
4297
|
+
* #### Example:
|
|
4289
4298
|
*
|
|
4290
4299
|
* Model.where({ _id: id }).update({ title: 'words' });
|
|
4291
4300
|
*
|
|
@@ -4303,11 +4312,11 @@ Query.prototype._replaceOne = wrapThunk(function(callback) {
|
|
|
4303
4312
|
* - `read`
|
|
4304
4313
|
* - `writeConcern`
|
|
4305
4314
|
*
|
|
4306
|
-
* #### Note
|
|
4315
|
+
* #### Note:
|
|
4307
4316
|
*
|
|
4308
4317
|
* Passing an empty object `{}` as the doc will result in a no-op. The update operation will be ignored and the callback executed without sending the command to MongoDB.
|
|
4309
4318
|
*
|
|
4310
|
-
* #### Note
|
|
4319
|
+
* #### Note:
|
|
4311
4320
|
*
|
|
4312
4321
|
* The operation is only executed when a callback is passed. To force execution without a callback, we must first call update() and then execute it by using the `exec()` method.
|
|
4313
4322
|
*
|
|
@@ -5038,7 +5047,7 @@ function castQuery(query) {
|
|
|
5038
5047
|
* a response for each query has also been returned, the results are passed to
|
|
5039
5048
|
* the callback.
|
|
5040
5049
|
*
|
|
5041
|
-
* @param {Object|String|
|
|
5050
|
+
* @param {Object|String|String[]} path either the path(s) to populate or an object specifying all parameters
|
|
5042
5051
|
* @param {Object|String} [select] Field selection for the population query
|
|
5043
5052
|
* @param {Model} [model] The model you wish to use for population. If not specified, populate will look up the model by the name in the Schema's `ref` field.
|
|
5044
5053
|
* @param {Object} [match] Conditions for the population query
|
|
@@ -5164,7 +5173,7 @@ function _getPopulatedPaths(list, arr, prefix) {
|
|
|
5164
5173
|
/**
|
|
5165
5174
|
* Casts this query to the schema of `model`
|
|
5166
5175
|
*
|
|
5167
|
-
* #### Note
|
|
5176
|
+
* #### Note:
|
|
5168
5177
|
*
|
|
5169
5178
|
* If `obj` is present, it is cast instead of this query.
|
|
5170
5179
|
*
|
|
@@ -5289,7 +5298,7 @@ Query.prototype._applyPaths = function applyPaths() {
|
|
|
5289
5298
|
*
|
|
5290
5299
|
* The `.cursor()` function triggers pre find hooks, but **not** post find hooks.
|
|
5291
5300
|
*
|
|
5292
|
-
* #### Example
|
|
5301
|
+
* #### Example:
|
|
5293
5302
|
*
|
|
5294
5303
|
* // There are 2 ways to use a cursor. First, as a stream:
|
|
5295
5304
|
* Thing.
|
|
@@ -5360,7 +5369,7 @@ Query.prototype.maxscan = Query.base.maxScan;
|
|
|
5360
5369
|
/**
|
|
5361
5370
|
* Sets the tailable option (for use with capped collections).
|
|
5362
5371
|
*
|
|
5363
|
-
* #### Example
|
|
5372
|
+
* #### Example:
|
|
5364
5373
|
*
|
|
5365
5374
|
* query.tailable(); // true
|
|
5366
5375
|
* query.tailable(true);
|
|
@@ -5369,7 +5378,7 @@ Query.prototype.maxscan = Query.base.maxScan;
|
|
|
5369
5378
|
* // Set both `tailable` and `awaitData` options
|
|
5370
5379
|
* query.tailable({ awaitData: true });
|
|
5371
5380
|
*
|
|
5372
|
-
* #### Note
|
|
5381
|
+
* #### Note:
|
|
5373
5382
|
*
|
|
5374
5383
|
* Cannot be used with `distinct()`
|
|
5375
5384
|
*
|
|
@@ -5410,7 +5419,7 @@ Query.prototype.tailable = function(val, opts) {
|
|
|
5410
5419
|
/**
|
|
5411
5420
|
* Declares an intersects query for `geometry()`.
|
|
5412
5421
|
*
|
|
5413
|
-
* #### Example
|
|
5422
|
+
* #### Example:
|
|
5414
5423
|
*
|
|
5415
5424
|
* query.where('path').intersects().geometry({
|
|
5416
5425
|
* type: 'LineString',
|
|
@@ -5443,7 +5452,7 @@ Query.prototype.tailable = function(val, opts) {
|
|
|
5443
5452
|
/**
|
|
5444
5453
|
* Specifies a `$geometry` condition
|
|
5445
5454
|
*
|
|
5446
|
-
* #### Example
|
|
5455
|
+
* #### Example:
|
|
5447
5456
|
*
|
|
5448
5457
|
* const polyA = [[[ 10, 20 ], [ 10, 40 ], [ 30, 40 ], [ 30, 20 ]]]
|
|
5449
5458
|
* query.where('loc').within().geometry({ type: 'Polygon', coordinates: polyA })
|
|
@@ -5485,7 +5494,7 @@ Query.prototype.tailable = function(val, opts) {
|
|
|
5485
5494
|
*
|
|
5486
5495
|
* These operators return documents sorted by distance.
|
|
5487
5496
|
*
|
|
5488
|
-
* #### Example
|
|
5497
|
+
* #### Example:
|
|
5489
5498
|
*
|
|
5490
5499
|
* query.where('loc').near({ center: [10, 10] });
|
|
5491
5500
|
* query.where('loc').near({ center: [10, 10], maxDistance: 5 });
|
|
@@ -5568,13 +5577,13 @@ Query.prototype.near = function() {
|
|
|
5568
5577
|
/**
|
|
5569
5578
|
* _DEPRECATED_ Specifies a `$nearSphere` condition
|
|
5570
5579
|
*
|
|
5571
|
-
* #### Example
|
|
5580
|
+
* #### Example:
|
|
5572
5581
|
*
|
|
5573
5582
|
* query.where('loc').nearSphere({ center: [10, 10], maxDistance: 5 });
|
|
5574
5583
|
*
|
|
5575
5584
|
* **Deprecated.** Use `query.near()` instead with the `spherical` option set to `true`.
|
|
5576
5585
|
*
|
|
5577
|
-
* #### Example
|
|
5586
|
+
* #### Example:
|
|
5578
5587
|
*
|
|
5579
5588
|
* query.where('loc').near({ center: [10, 10], spherical: true });
|
|
5580
5589
|
*
|
|
@@ -5597,7 +5606,7 @@ Query.prototype.nearSphere = function() {
|
|
|
5597
5606
|
* You do not need to call this function explicitly, the JavaScript runtime
|
|
5598
5607
|
* will call it for you.
|
|
5599
5608
|
*
|
|
5600
|
-
* #### Example
|
|
5609
|
+
* #### Example:
|
|
5601
5610
|
*
|
|
5602
5611
|
* for await (const doc of Model.aggregate([{ $sort: { name: 1 } }])) {
|
|
5603
5612
|
* console.log(doc.name);
|
|
@@ -5625,7 +5634,7 @@ if (Symbol.asyncIterator != null) {
|
|
|
5625
5634
|
/**
|
|
5626
5635
|
* Specifies a `$polygon` condition
|
|
5627
5636
|
*
|
|
5628
|
-
* #### Example
|
|
5637
|
+
* #### Example:
|
|
5629
5638
|
*
|
|
5630
5639
|
* query.where('loc').within().polygon([10, 20], [13, 25], [7, 15]);
|
|
5631
5640
|
* query.polygon('loc', [10, 20], [13, 25], [7, 15]);
|
|
@@ -5644,7 +5653,7 @@ if (Symbol.asyncIterator != null) {
|
|
|
5644
5653
|
/**
|
|
5645
5654
|
* Specifies a `$box` condition
|
|
5646
5655
|
*
|
|
5647
|
-
* #### Example
|
|
5656
|
+
* #### Example:
|
|
5648
5657
|
*
|
|
5649
5658
|
* const lowerLeft = [40.73083, -73.99756]
|
|
5650
5659
|
* const upperRight= [40.741404, -73.988135]
|
|
@@ -5658,8 +5667,8 @@ if (Symbol.asyncIterator != null) {
|
|
|
5658
5667
|
* @see $box https://docs.mongodb.org/manual/reference/operator/box/
|
|
5659
5668
|
* @see within() Query#within #query_Query-within
|
|
5660
5669
|
* @see https://www.mongodb.org/display/DOCS/Geospatial+Indexing
|
|
5661
|
-
* @param {Object}
|
|
5662
|
-
* @param [
|
|
5670
|
+
* @param {Object|Array<Number>} val1 Lower Left Coordinates OR a object of lower-left(ll) and upper-right(ur) Coordinates
|
|
5671
|
+
* @param {Array<Number>} [val2] Upper Right Coordinates
|
|
5663
5672
|
* @return {Query} this
|
|
5664
5673
|
* @api public
|
|
5665
5674
|
*/
|
|
@@ -5681,7 +5690,7 @@ Query.prototype.box = function(ll, ur) {
|
|
|
5681
5690
|
/**
|
|
5682
5691
|
* Specifies a `$center` or `$centerSphere` condition.
|
|
5683
5692
|
*
|
|
5684
|
-
* #### Example
|
|
5693
|
+
* #### Example:
|
|
5685
5694
|
*
|
|
5686
5695
|
* const area = { center: [50, 50], radius: 10, unique: true }
|
|
5687
5696
|
* query.where('loc').within().circle(area)
|
|
@@ -5726,7 +5735,7 @@ Query.prototype.center = Query.base.circle;
|
|
|
5726
5735
|
*
|
|
5727
5736
|
* **Deprecated.** Use [circle](#query_Query-circle) instead.
|
|
5728
5737
|
*
|
|
5729
|
-
* #### Example
|
|
5738
|
+
* #### Example:
|
|
5730
5739
|
*
|
|
5731
5740
|
* const area = { center: [50, 50], radius: 10 };
|
|
5732
5741
|
* query.where('loc').within().centerSphere(area);
|
|
@@ -314,24 +314,28 @@ SubdocumentPath.prototype.discriminator = function(name, schema, options) {
|
|
|
314
314
|
return this.caster.discriminators[name];
|
|
315
315
|
};
|
|
316
316
|
|
|
317
|
+
/*!
|
|
318
|
+
* ignore
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
SubdocumentPath.defaultOptions = {};
|
|
322
|
+
|
|
317
323
|
/**
|
|
318
324
|
* Sets a default option for all SubdocumentPath instances.
|
|
319
325
|
*
|
|
320
326
|
* #### Example:
|
|
321
327
|
*
|
|
322
328
|
* // Make all numbers have option `min` equal to 0.
|
|
323
|
-
* mongoose.Schema.
|
|
329
|
+
* mongoose.Schema.SubdocumentPath.set('required', true);
|
|
324
330
|
*
|
|
325
|
-
* @param {String} option
|
|
326
|
-
* @param {
|
|
327
|
-
* @return {
|
|
331
|
+
* @param {String} option The option you'd like to set the value for
|
|
332
|
+
* @param {Any} value value for option
|
|
333
|
+
* @return {void}
|
|
328
334
|
* @function set
|
|
329
335
|
* @static
|
|
330
336
|
* @api public
|
|
331
337
|
*/
|
|
332
338
|
|
|
333
|
-
SubdocumentPath.defaultOptions = {};
|
|
334
|
-
|
|
335
339
|
SubdocumentPath.set = SchemaType.set;
|
|
336
340
|
|
|
337
341
|
/*!
|
package/lib/schema/array.js
CHANGED
|
@@ -138,7 +138,7 @@ SchemaArray.schemaName = 'Array';
|
|
|
138
138
|
*
|
|
139
139
|
* - `castNonArrays`: `true` by default. If `false`, Mongoose will throw a CastError when a value isn't an array. If `true`, Mongoose will wrap the provided value in an array before casting.
|
|
140
140
|
*
|
|
141
|
-
* @static
|
|
141
|
+
* @static
|
|
142
142
|
* @api public
|
|
143
143
|
*/
|
|
144
144
|
|
|
@@ -161,8 +161,8 @@ SchemaArray.defaultOptions = {};
|
|
|
161
161
|
* const User = mongoose.model('User', new Schema({ test: Array }));
|
|
162
162
|
* new User({ }).validateSync().errors.test.message; // Path `test` is required.
|
|
163
163
|
*
|
|
164
|
-
* @param {String} option
|
|
165
|
-
* @param {
|
|
164
|
+
* @param {String} option The option you'd like to set the value for
|
|
165
|
+
* @param {Any} value value for option
|
|
166
166
|
* @return {undefined}
|
|
167
167
|
* @function set
|
|
168
168
|
* @api public
|
package/lib/schema/boolean.js
CHANGED
|
@@ -55,8 +55,8 @@ SchemaBoolean._cast = castBoolean;
|
|
|
55
55
|
* const Order = mongoose.model('Order', new Schema({ isPaid: Boolean }));
|
|
56
56
|
* new Order({ }).isPaid; // false
|
|
57
57
|
*
|
|
58
|
-
* @param {String} option
|
|
59
|
-
* @param {
|
|
58
|
+
* @param {String} option The option you'd like to set the value for
|
|
59
|
+
* @param {Any} value value for option
|
|
60
60
|
* @return {undefined}
|
|
61
61
|
* @function set
|
|
62
62
|
* @static
|
|
@@ -156,7 +156,7 @@ SchemaBoolean.prototype.checkRequired = function(value) {
|
|
|
156
156
|
* new M({ b: 'affirmative' }).b; // true
|
|
157
157
|
*
|
|
158
158
|
* @property convertToTrue
|
|
159
|
-
* @type Set
|
|
159
|
+
* @type {Set}
|
|
160
160
|
* @api public
|
|
161
161
|
*/
|
|
162
162
|
|
|
@@ -176,7 +176,7 @@ Object.defineProperty(SchemaBoolean, 'convertToTrue', {
|
|
|
176
176
|
* new M({ b: 'nay' }).b; // false
|
|
177
177
|
*
|
|
178
178
|
* @property convertToFalse
|
|
179
|
-
* @type Set
|
|
179
|
+
* @type {Set}
|
|
180
180
|
* @api public
|
|
181
181
|
*/
|
|
182
182
|
|
|
@@ -189,7 +189,7 @@ Object.defineProperty(SchemaBoolean, 'convertToFalse', {
|
|
|
189
189
|
* Casts to boolean
|
|
190
190
|
*
|
|
191
191
|
* @param {Object} value
|
|
192
|
-
* @param {Object} model
|
|
192
|
+
* @param {Object} model this value is optional
|
|
193
193
|
* @api private
|
|
194
194
|
*/
|
|
195
195
|
|