mongoose 6.4.1 → 6.4.4
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 +4 -2
- package/lib/aggregate.js +3 -2
- package/lib/cast/date.js +1 -1
- package/lib/cast/decimal128.js +1 -1
- package/lib/cast/objectid.js +1 -1
- package/lib/cast.js +1 -1
- package/lib/connection.js +9 -9
- package/lib/cursor/AggregationCursor.js +3 -2
- package/lib/cursor/QueryCursor.js +5 -4
- package/lib/document.js +48 -16
- package/lib/drivers/node-mongodb-native/index.js +1 -1
- package/lib/error/index.js +12 -12
- package/lib/error/messages.js +2 -2
- package/lib/error/parallelValidate.js +1 -1
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +1 -1
- package/lib/helpers/aggregate/stringifyFunctionOperators.js +1 -1
- package/lib/helpers/arrayDepth.js +1 -1
- package/lib/helpers/cursor/eachAsync.js +1 -1
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
- package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +1 -1
- package/lib/helpers/discriminator/getConstructor.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/lib/helpers/document/handleSpreadDoc.js +1 -1
- package/lib/helpers/each.js +1 -1
- package/lib/helpers/get.js +1 -1
- package/lib/helpers/getConstructorName.js +1 -1
- package/lib/helpers/getDefaultBulkwriteResult.js +1 -1
- package/lib/helpers/indexes/applySchemaCollation.js +1 -1
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
- package/lib/helpers/indexes/isTextIndex.js +1 -1
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +1 -1
- package/lib/helpers/isPromise.js +1 -1
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/applyStaticHooks.js +1 -1
- package/lib/helpers/once.js +1 -1
- package/lib/helpers/path/flattenObjectWithDottedPaths.js +1 -1
- package/lib/helpers/path/parentPaths.js +1 -1
- package/lib/helpers/path/setDottedPath.js +1 -1
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/SkipPopulateValue.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +1 -1
- package/lib/helpers/populate/assignVals.js +1 -1
- package/lib/helpers/populate/createPopulateQueryFilter.js +1 -1
- package/lib/helpers/populate/getModelsMapForPopulate.js +1 -1
- package/lib/helpers/populate/leanPopulateMap.js +1 -1
- package/lib/helpers/populate/lookupLocalFields.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
- package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
- package/lib/helpers/populate/validateRef.js +1 -1
- package/lib/helpers/printJestWarning.js +1 -1
- package/lib/helpers/processConnectionOptions.js +1 -1
- package/lib/helpers/projection/applyProjection.js +1 -1
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/parseProjection.js +1 -1
- package/lib/helpers/query/applyGlobalOption.js +1 -1
- package/lib/helpers/query/applyQueryMiddleware.js +1 -1
- package/lib/helpers/query/cast$expr.js +1 -1
- package/lib/helpers/query/castFilterPath.js +1 -1
- package/lib/helpers/query/castUpdate.js +4 -4
- package/lib/helpers/query/sanitizeFilter.js +1 -1
- package/lib/helpers/query/sanitizeProjection.js +1 -1
- package/lib/helpers/query/trusted.js +1 -1
- package/lib/helpers/query/validOps.js +1 -1
- package/lib/helpers/query/wrapThunk.js +1 -1
- package/lib/helpers/schema/addAutoId.js +1 -1
- package/lib/helpers/schema/applyPlugins.js +1 -1
- package/lib/helpers/schema/cleanPositionalOperators.js +1 -1
- package/lib/helpers/schema/getKeysInSchemaOrder.js +1 -1
- package/lib/helpers/schema/getPath.js +1 -1
- package/lib/helpers/schema/handleIdOption.js +1 -1
- package/lib/helpers/schema/handleTimestampOption.js +1 -1
- package/lib/helpers/specialProperties.js +1 -1
- package/lib/helpers/symbols.js +1 -1
- package/lib/helpers/timers.js +1 -1
- package/lib/helpers/timestamps/setupTimestamps.js +1 -1
- package/lib/helpers/topology/allServersUnknown.js +1 -1
- package/lib/helpers/topology/isAtlas.js +1 -1
- package/lib/helpers/topology/isSSLError.js +1 -1
- package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
- package/lib/helpers/update/castArrayFilters.js +1 -1
- package/lib/helpers/update/moveImmutableProperties.js +1 -1
- package/lib/helpers/update/removeUnusedArrayFilters.js +1 -1
- package/lib/helpers/update/updatedPathsByArrayFilter.js +1 -1
- package/lib/index.js +7 -4
- package/lib/model.js +22 -21
- package/lib/options/PopulateOptions.js +1 -1
- package/lib/options/SchemaArrayOptions.js +3 -3
- package/lib/options/SchemaBufferOptions.js +2 -2
- package/lib/options/SchemaDateOptions.js +3 -3
- package/lib/options/SchemaDocumentArrayOptions.js +3 -3
- package/lib/options/SchemaMapOptions.js +2 -2
- package/lib/options/SchemaNumberOptions.js +5 -5
- package/lib/options/SchemaObjectIdOptions.js +3 -3
- package/lib/options/SchemaStringOptions.js +8 -8
- package/lib/options/SchemaSubdocumentOptions.js +2 -2
- package/lib/options/SchemaTypeOptions.js +15 -15
- package/lib/options/VirtualOptions.js +12 -12
- package/lib/options/propertyOptions.js +1 -1
- package/lib/options/removeOptions.js +1 -1
- package/lib/options/saveOptions.js +1 -1
- package/lib/plugins/trackTransaction.js +1 -1
- package/lib/query.js +74 -71
- 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/symbols.js +1 -1
- package/lib/schema.js +72 -37
- package/lib/schematype.js +9 -10
- package/lib/types/DocumentArray/methods/index.js +2 -2
- package/lib/types/buffer.js +30 -28
- package/lib/types/decimal128.js +4 -4
- package/lib/types/map.js +70 -0
- package/lib/types/objectid.js +1 -1
- package/lib/types/subdocument.js +1 -1
- package/lib/virtualtype.js +5 -5
- package/package.json +13 -13
- package/types/collection.d.ts +1 -1
- package/types/document.d.ts +4 -4
- package/types/expressions.d.ts +27 -8
- package/types/index.d.ts +2 -1
- package/types/indexes.d.ts +2 -2
- package/types/inferschematype.d.ts +51 -33
- package/types/middlewares.d.ts +1 -1
- package/types/models.d.ts +8 -7
- package/types/mongooseoptions.d.ts +1 -1
- package/types/pipelinestage.d.ts +1 -1
- package/types/query.d.ts +6 -1
- package/types/schemaoptions.d.ts +1 -1
- package/types/utility.d.ts +7 -0
package/lib/schema/decimal128.js
CHANGED
|
@@ -56,8 +56,8 @@ Decimal128._cast = castDecimal128;
|
|
|
56
56
|
* const User = mongoose.model('User', new Schema({ test: mongoose.Decimal128 }));
|
|
57
57
|
* new User({ }).validateSync().errors.test.message; // Path `test` is required.
|
|
58
58
|
*
|
|
59
|
-
* @param {String} option
|
|
60
|
-
* @param {
|
|
59
|
+
* @param {String} option The option you'd like to set the value for
|
|
60
|
+
* @param {Any} value value for option
|
|
61
61
|
* @return {undefined}
|
|
62
62
|
* @function set
|
|
63
63
|
* @static
|
|
@@ -536,9 +536,9 @@ DocumentArrayPath.prototype.applyGetters = function(value, scope) {
|
|
|
536
536
|
* Scopes paths selected in a query to this array.
|
|
537
537
|
* Necessary for proper default application of subdocument values.
|
|
538
538
|
*
|
|
539
|
-
* @param {DocumentArrayPath} array
|
|
540
|
-
* @param {Object|undefined} fields
|
|
541
|
-
* @param {Boolean|undefined} init
|
|
539
|
+
* @param {DocumentArrayPath} array the array to scope `fields` paths
|
|
540
|
+
* @param {Object|undefined} fields the root fields selected in the query
|
|
541
|
+
* @param {Boolean|undefined} init if we are being created part of a query result
|
|
542
542
|
*/
|
|
543
543
|
|
|
544
544
|
function scopePaths(array, fields, init) {
|
|
@@ -572,6 +572,12 @@ function scopePaths(array, fields, init) {
|
|
|
572
572
|
return hasKeys && selected || undefined;
|
|
573
573
|
}
|
|
574
574
|
|
|
575
|
+
/*!
|
|
576
|
+
* ignore
|
|
577
|
+
*/
|
|
578
|
+
|
|
579
|
+
DocumentArrayPath.defaultOptions = {};
|
|
580
|
+
|
|
575
581
|
/**
|
|
576
582
|
* Sets a default option for all DocumentArray instances.
|
|
577
583
|
*
|
|
@@ -580,16 +586,14 @@ function scopePaths(array, fields, init) {
|
|
|
580
586
|
* // Make all numbers have option `min` equal to 0.
|
|
581
587
|
* mongoose.Schema.DocumentArray.set('_id', false);
|
|
582
588
|
*
|
|
583
|
-
* @param {String} option
|
|
584
|
-
* @param {
|
|
585
|
-
* @return {
|
|
589
|
+
* @param {String} option The name of the option you'd like to set (e.g. trim, lowercase, etc...)
|
|
590
|
+
* @param {Any} value The value of the option you'd like to set.
|
|
591
|
+
* @return {void}
|
|
586
592
|
* @function set
|
|
587
593
|
* @static
|
|
588
594
|
* @api public
|
|
589
595
|
*/
|
|
590
596
|
|
|
591
|
-
DocumentArrayPath.defaultOptions = {};
|
|
592
|
-
|
|
593
597
|
DocumentArrayPath.set = SchemaType.set;
|
|
594
598
|
|
|
595
599
|
/*!
|
package/lib/schema/mixed.js
CHANGED
|
@@ -84,8 +84,8 @@ Mixed.get = SchemaType.get;
|
|
|
84
84
|
* const User = mongoose.model('User', new Schema({ test: mongoose.Mixed }));
|
|
85
85
|
* new User({ }).validateSync().errors.test.message; // Path `test` is required.
|
|
86
86
|
*
|
|
87
|
-
* @param {String} option
|
|
88
|
-
* @param {
|
|
87
|
+
* @param {String} option The option you'd like to set the value for
|
|
88
|
+
* @param {Any} value value for option
|
|
89
89
|
* @return {undefined}
|
|
90
90
|
* @function set
|
|
91
91
|
* @static
|
package/lib/schema/number.js
CHANGED
|
@@ -57,8 +57,8 @@ SchemaNumber.get = SchemaType.get;
|
|
|
57
57
|
* const Order = mongoose.model('Order', new Schema({ amount: Number }));
|
|
58
58
|
* new Order({ amount: -10 }).validateSync().errors.amount.message; // Path `amount` must be larger than 0.
|
|
59
59
|
*
|
|
60
|
-
* @param {String} option
|
|
61
|
-
* @param {
|
|
60
|
+
* @param {String} option The option you'd like to set the value for
|
|
61
|
+
* @param {Any} value value for option
|
|
62
62
|
* @return {undefined}
|
|
63
63
|
* @function set
|
|
64
64
|
* @static
|
package/lib/schema/objectid.js
CHANGED
|
@@ -84,8 +84,8 @@ ObjectId.get = SchemaType.get;
|
|
|
84
84
|
* const Order = mongoose.model('Order', new Schema({ userId: ObjectId }));
|
|
85
85
|
* new Order({ }).validateSync().errors.userId.message; // Path `userId` is required.
|
|
86
86
|
*
|
|
87
|
-
* @param {String} option
|
|
88
|
-
* @param {
|
|
87
|
+
* @param {String} option The option you'd like to set the value for
|
|
88
|
+
* @param {Any} value value for option
|
|
89
89
|
* @return {undefined}
|
|
90
90
|
* @function set
|
|
91
91
|
* @static
|
package/lib/schema/string.js
CHANGED
|
@@ -133,8 +133,8 @@ SchemaString.get = SchemaType.get;
|
|
|
133
133
|
* const User = mongoose.model('User', new Schema({ name: String }));
|
|
134
134
|
* new User({ name: ' John Doe ' }).name; // 'John Doe'
|
|
135
135
|
*
|
|
136
|
-
* @param {String} option
|
|
137
|
-
* @param {
|
|
136
|
+
* @param {String} option The option you'd like to set the value for
|
|
137
|
+
* @param {Any} value value for option
|
|
138
138
|
* @return {undefined}
|
|
139
139
|
* @function set
|
|
140
140
|
* @static
|
package/lib/schema/symbols.js
CHANGED
package/lib/schema.js
CHANGED
|
@@ -79,6 +79,7 @@ let id = 0;
|
|
|
79
79
|
* - [pluginTags](/docs/guide.html#pluginTags): array of strings - defaults to `undefined`. If set and plugin called with `tags` option, will only apply that plugin to schemas with a matching tag.
|
|
80
80
|
*
|
|
81
81
|
* #### Options for Nested Schemas:
|
|
82
|
+
*
|
|
82
83
|
* - `excludeIndexes`: bool - defaults to `false`. If `true`, skip building indexes on this schema's paths.
|
|
83
84
|
*
|
|
84
85
|
* #### Note:
|
|
@@ -233,6 +234,7 @@ Object.defineProperty(Schema.prototype, 'childSchemas', {
|
|
|
233
234
|
* You do not need to interact with this property at all to use mongoose.
|
|
234
235
|
*
|
|
235
236
|
* #### Example:
|
|
237
|
+
*
|
|
236
238
|
* const schema = new Schema({});
|
|
237
239
|
* schema.virtual('answer').get(() => 42);
|
|
238
240
|
*
|
|
@@ -272,6 +274,7 @@ Schema.prototype.obj;
|
|
|
272
274
|
* in this schema, and the values are instances of the SchemaType class.
|
|
273
275
|
*
|
|
274
276
|
* #### Example:
|
|
277
|
+
*
|
|
275
278
|
* const schema = new Schema({ name: String }, { _id: false });
|
|
276
279
|
* schema.paths; // { name: SchemaString { ... } }
|
|
277
280
|
*
|
|
@@ -290,6 +293,7 @@ Schema.prototype.paths;
|
|
|
290
293
|
* Schema as a tree
|
|
291
294
|
*
|
|
292
295
|
* #### Example:
|
|
296
|
+
*
|
|
293
297
|
* {
|
|
294
298
|
* '_id' : ObjectId
|
|
295
299
|
* , 'nested' : {
|
|
@@ -395,8 +399,8 @@ Schema.prototype._clone = function _clone(Constructor) {
|
|
|
395
399
|
* newSchema.path('name'); // SchemaString { ... }
|
|
396
400
|
* newSchema.path('age'); // undefined
|
|
397
401
|
*
|
|
398
|
-
* @param {
|
|
399
|
-
* @param {Object} [options]
|
|
402
|
+
* @param {String[]} paths List of Paths to pick for the new Schema
|
|
403
|
+
* @param {Object} [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`). Defaults to `this.options` if not set.
|
|
400
404
|
* @return {Schema}
|
|
401
405
|
* @api public
|
|
402
406
|
*/
|
|
@@ -426,8 +430,8 @@ Schema.prototype.pick = function(paths, options) {
|
|
|
426
430
|
/**
|
|
427
431
|
* Returns default options for this schema, merged with `options`.
|
|
428
432
|
*
|
|
429
|
-
* @param {Object} options
|
|
430
|
-
* @return {Object}
|
|
433
|
+
* @param {Object} [options] Options to overwrite the default options
|
|
434
|
+
* @return {Object} The merged options of `options` and the default options
|
|
431
435
|
* @api private
|
|
432
436
|
*/
|
|
433
437
|
|
|
@@ -477,7 +481,7 @@ Schema.prototype.defaultOptions = function(options) {
|
|
|
477
481
|
* Inherit a Schema by applying a discriminator on an existing Schema.
|
|
478
482
|
*
|
|
479
483
|
*
|
|
480
|
-
* ####Example:
|
|
484
|
+
* #### Example:
|
|
481
485
|
*
|
|
482
486
|
* const options = { discriminatorKey: 'kind' };
|
|
483
487
|
*
|
|
@@ -648,7 +652,7 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
648
652
|
* removeIndex only removes indexes from your schema object. Does **not** affect the indexes
|
|
649
653
|
* in MongoDB.
|
|
650
654
|
*
|
|
651
|
-
* ####Example:
|
|
655
|
+
* #### Example:
|
|
652
656
|
*
|
|
653
657
|
* const ToySchema = new Schema({ name: String, color: String, price: Number });
|
|
654
658
|
*
|
|
@@ -701,7 +705,7 @@ Schema.prototype.removeIndex = function removeIndex(index) {
|
|
|
701
705
|
* clearIndexes only removes indexes from your schema object. Does **not** affect the indexes
|
|
702
706
|
* in MongoDB.
|
|
703
707
|
*
|
|
704
|
-
* ####Example:
|
|
708
|
+
* #### Example:
|
|
705
709
|
*
|
|
706
710
|
* const ToySchema = new Schema({ name: String, color: String, price: Number });
|
|
707
711
|
* ToySchema.index({ name: 1 });
|
|
@@ -755,6 +759,10 @@ Schema.prototype.clearIndexes = function clearIndexes() {
|
|
|
755
759
|
*
|
|
756
760
|
* const schema = new Schema(..);
|
|
757
761
|
* schema.methods.init = function () {} // potentially breaking
|
|
762
|
+
*
|
|
763
|
+
* @property reserved
|
|
764
|
+
* @memberOf Schema
|
|
765
|
+
* @static
|
|
758
766
|
*/
|
|
759
767
|
|
|
760
768
|
Schema.reserved = Object.create(null);
|
|
@@ -788,13 +796,13 @@ reserved.collection = 1;
|
|
|
788
796
|
* Sets a path (if arity 2)
|
|
789
797
|
* Gets a path (if arity 1)
|
|
790
798
|
*
|
|
791
|
-
* #### Example
|
|
799
|
+
* #### Example:
|
|
792
800
|
*
|
|
793
801
|
* schema.path('name') // returns a SchemaType
|
|
794
802
|
* schema.path('name', Number) // changes the schemaType of `name` to Number
|
|
795
803
|
*
|
|
796
|
-
* @param {String} path
|
|
797
|
-
* @param {Object}
|
|
804
|
+
* @param {String} path The name of the Path to get / set
|
|
805
|
+
* @param {Object} [obj] The Type to set the path to, if provided the path will be SET, otherwise the path will be GET
|
|
798
806
|
* @api public
|
|
799
807
|
*/
|
|
800
808
|
|
|
@@ -1059,6 +1067,7 @@ Object.defineProperty(Schema.prototype, 'base', {
|
|
|
1059
1067
|
*
|
|
1060
1068
|
* @param {String} path
|
|
1061
1069
|
* @param {Object} obj constructor
|
|
1070
|
+
* @param {Object} options
|
|
1062
1071
|
* @api private
|
|
1063
1072
|
*/
|
|
1064
1073
|
|
|
@@ -1316,6 +1325,7 @@ Schema.prototype.eachPath = function(fn) {
|
|
|
1316
1325
|
* Returns an Array of path strings that are required by this schema.
|
|
1317
1326
|
*
|
|
1318
1327
|
* #### Example:
|
|
1328
|
+
*
|
|
1319
1329
|
* const s = new Schema({
|
|
1320
1330
|
* name: { type: String, required: true },
|
|
1321
1331
|
* age: { type: String, required: true },
|
|
@@ -1324,7 +1334,7 @@ Schema.prototype.eachPath = function(fn) {
|
|
|
1324
1334
|
* s.requiredPaths(); // [ 'age', 'name' ]
|
|
1325
1335
|
*
|
|
1326
1336
|
* @api public
|
|
1327
|
-
* @param {Boolean} invalidate
|
|
1337
|
+
* @param {Boolean} invalidate Refresh the cache
|
|
1328
1338
|
* @return {Array}
|
|
1329
1339
|
*/
|
|
1330
1340
|
|
|
@@ -1545,7 +1555,7 @@ Schema.prototype.queue = function(name, args) {
|
|
|
1545
1555
|
/**
|
|
1546
1556
|
* Defines a pre hook for the model.
|
|
1547
1557
|
*
|
|
1548
|
-
* #### Example
|
|
1558
|
+
* #### Example:
|
|
1549
1559
|
*
|
|
1550
1560
|
* const toySchema = new Schema({ name: String, created: Date });
|
|
1551
1561
|
*
|
|
@@ -1577,7 +1587,7 @@ Schema.prototype.queue = function(name, args) {
|
|
|
1577
1587
|
* // Runs when you call `doc.deleteOne()`
|
|
1578
1588
|
* });
|
|
1579
1589
|
*
|
|
1580
|
-
* @param {String|RegExp} The method name or regular expression to match method name
|
|
1590
|
+
* @param {String|RegExp|String[]} methodName The method name or regular expression to match method name
|
|
1581
1591
|
* @param {Object} [options]
|
|
1582
1592
|
* @param {Boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware. For example, set `options.document` to `true` to apply this hook to `Document#deleteOne()` rather than `Query#deleteOne()`.
|
|
1583
1593
|
* @param {Boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
|
|
@@ -1633,7 +1643,7 @@ Schema.prototype.pre = function(name) {
|
|
|
1633
1643
|
* console.log('this fires after the post find hook');
|
|
1634
1644
|
* });
|
|
1635
1645
|
*
|
|
1636
|
-
* @param {String|RegExp} The method name or regular expression to match method name
|
|
1646
|
+
* @param {String|RegExp|String[]} methodName The method name or regular expression to match method name
|
|
1637
1647
|
* @param {Object} [options]
|
|
1638
1648
|
* @param {Boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware.
|
|
1639
1649
|
* @param {Boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
|
|
@@ -1673,8 +1683,14 @@ Schema.prototype.post = function(name) {
|
|
|
1673
1683
|
* s.plugin(schema => console.log(schema.path('name').path));
|
|
1674
1684
|
* mongoose.model('Test', s); // Prints 'name'
|
|
1675
1685
|
*
|
|
1676
|
-
*
|
|
1677
|
-
*
|
|
1686
|
+
* Or with Options:
|
|
1687
|
+
*
|
|
1688
|
+
* const s = new Schema({ name: String });
|
|
1689
|
+
* s.plugin((schema, opts) => console.log(opts.text, schema.path('name').path), { text: "Schema Path Name:" });
|
|
1690
|
+
* mongoose.model('Test', s); // Prints 'Schema Path Name: name'
|
|
1691
|
+
*
|
|
1692
|
+
* @param {Function} plugin The Plugin's callback
|
|
1693
|
+
* @param {Object} [opts] Options to pass to the plugin
|
|
1678
1694
|
* @see plugins
|
|
1679
1695
|
* @api public
|
|
1680
1696
|
*/
|
|
@@ -1701,7 +1717,7 @@ Schema.prototype.plugin = function(fn, opts) {
|
|
|
1701
1717
|
/**
|
|
1702
1718
|
* Adds an instance method to documents constructed from Models compiled from this schema.
|
|
1703
1719
|
*
|
|
1704
|
-
* #### Example
|
|
1720
|
+
* #### Example:
|
|
1705
1721
|
*
|
|
1706
1722
|
* const schema = kittySchema = new Schema(..);
|
|
1707
1723
|
*
|
|
@@ -1722,13 +1738,14 @@ Schema.prototype.plugin = function(fn, opts) {
|
|
|
1722
1738
|
* });
|
|
1723
1739
|
*
|
|
1724
1740
|
* // later
|
|
1741
|
+
* const fizz = new Kitty;
|
|
1725
1742
|
* fizz.purr();
|
|
1726
1743
|
* fizz.scratch();
|
|
1727
1744
|
*
|
|
1728
1745
|
* NOTE: `Schema.method()` adds instance methods to the `Schema.methods` object. You can also add instance methods directly to the `Schema.methods` object as seen in the [guide](/docs/guide.html#methods)
|
|
1729
1746
|
*
|
|
1730
|
-
* @param {String|Object}
|
|
1731
|
-
* @param {Function} [fn]
|
|
1747
|
+
* @param {String|Object} name The Method Name for a single function, or a Object of "string-function" pairs.
|
|
1748
|
+
* @param {Function} [fn] The Function in a single-function definition.
|
|
1732
1749
|
* @api public
|
|
1733
1750
|
*/
|
|
1734
1751
|
|
|
@@ -1748,7 +1765,7 @@ Schema.prototype.method = function(name, fn, options) {
|
|
|
1748
1765
|
/**
|
|
1749
1766
|
* Adds static "class" methods to Models compiled from this schema.
|
|
1750
1767
|
*
|
|
1751
|
-
* #### Example
|
|
1768
|
+
* #### Example:
|
|
1752
1769
|
*
|
|
1753
1770
|
* const schema = new Schema(..);
|
|
1754
1771
|
* // Equivalent to `schema.statics.findByName = function(name) {}`;
|
|
@@ -1759,10 +1776,21 @@ Schema.prototype.method = function(name, fn, options) {
|
|
|
1759
1776
|
* const Drink = mongoose.model('Drink', schema);
|
|
1760
1777
|
* await Drink.findByName('LaCroix');
|
|
1761
1778
|
*
|
|
1779
|
+
* If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as methods.
|
|
1780
|
+
*
|
|
1781
|
+
* schema.static({
|
|
1782
|
+
* findByName: function () {..}
|
|
1783
|
+
* , findByCost: function () {..}
|
|
1784
|
+
* });
|
|
1785
|
+
*
|
|
1786
|
+
* const Drink = mongoose.model('Drink', schema);
|
|
1787
|
+
* await Drink.findByName('LaCroix');
|
|
1788
|
+
* await Drink.findByCost(3);
|
|
1789
|
+
*
|
|
1762
1790
|
* If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as statics.
|
|
1763
1791
|
*
|
|
1764
|
-
* @param {String|Object} name
|
|
1765
|
-
* @param {Function} [fn]
|
|
1792
|
+
* @param {String|Object} name The Method Name for a single function, or a Object of "string-function" pairs.
|
|
1793
|
+
* @param {Function} [fn] The Function in a single-function definition.
|
|
1766
1794
|
* @api public
|
|
1767
1795
|
* @see Statics /docs/guide.html#statics
|
|
1768
1796
|
*/
|
|
@@ -1781,11 +1809,11 @@ Schema.prototype.static = function(name, fn) {
|
|
|
1781
1809
|
/**
|
|
1782
1810
|
* Defines an index (most likely compound) for this schema.
|
|
1783
1811
|
*
|
|
1784
|
-
* #### Example
|
|
1812
|
+
* #### Example:
|
|
1785
1813
|
*
|
|
1786
1814
|
* schema.index({ first: 1, last: -1 })
|
|
1787
1815
|
*
|
|
1788
|
-
* @param {Object} fields
|
|
1816
|
+
* @param {Object} fields The Fields to index, with the order, available values: `1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text'`
|
|
1789
1817
|
* @param {Object} [options] Options to pass to [MongoDB driver's `createIndex()` function](https://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#createIndex)
|
|
1790
1818
|
* @param {String | number} [options.expires=null] Mongoose-specific syntactic sugar, uses [ms](https://www.npmjs.com/package/ms) to convert `expires` option into seconds for the `expireAfterSeconds` in the above link.
|
|
1791
1819
|
* @api public
|
|
@@ -1806,14 +1834,14 @@ Schema.prototype.index = function(fields, options) {
|
|
|
1806
1834
|
/**
|
|
1807
1835
|
* Sets a schema option.
|
|
1808
1836
|
*
|
|
1809
|
-
* #### Example
|
|
1837
|
+
* #### Example:
|
|
1810
1838
|
*
|
|
1811
1839
|
* schema.set('strict'); // 'true' by default
|
|
1812
1840
|
* schema.set('strict', false); // Sets 'strict' to false
|
|
1813
1841
|
* schema.set('strict'); // 'false'
|
|
1814
1842
|
*
|
|
1815
|
-
* @param {String} key option
|
|
1816
|
-
* @param {Object} [value] if not passed, the
|
|
1843
|
+
* @param {String} key The name of the option to set the value to
|
|
1844
|
+
* @param {Object} [value] The value to set the option to, if not passed, the option will be reset to default
|
|
1817
1845
|
* @see Schema ./
|
|
1818
1846
|
* @api public
|
|
1819
1847
|
*/
|
|
@@ -1861,7 +1889,7 @@ Schema.prototype.set = function(key, value, _tags) {
|
|
|
1861
1889
|
* schema.set('strict', false);
|
|
1862
1890
|
* schema.get('strict'); // false
|
|
1863
1891
|
*
|
|
1864
|
-
* @param {String} key
|
|
1892
|
+
* @param {String} key The name of the Option to get the current value for
|
|
1865
1893
|
* @api public
|
|
1866
1894
|
* @return {Any} the option's value
|
|
1867
1895
|
*/
|
|
@@ -1870,16 +1898,17 @@ Schema.prototype.get = function(key) {
|
|
|
1870
1898
|
return this.options[key];
|
|
1871
1899
|
};
|
|
1872
1900
|
|
|
1901
|
+
const indexTypes = '2d 2dsphere hashed text'.split(' ');
|
|
1902
|
+
|
|
1873
1903
|
/**
|
|
1874
1904
|
* The allowed index types
|
|
1875
1905
|
*
|
|
1876
|
-
* @
|
|
1877
|
-
* @
|
|
1906
|
+
* @property {String[]} indexTypes
|
|
1907
|
+
* @memberOf Schema
|
|
1908
|
+
* @static
|
|
1878
1909
|
* @api public
|
|
1879
1910
|
*/
|
|
1880
1911
|
|
|
1881
|
-
const indexTypes = '2d 2dsphere hashed text'.split(' ');
|
|
1882
|
-
|
|
1883
1912
|
Object.defineProperty(Schema, 'indexTypes', {
|
|
1884
1913
|
get: function() {
|
|
1885
1914
|
return indexTypes;
|
|
@@ -1926,7 +1955,7 @@ Schema.prototype.indexes = function() {
|
|
|
1926
1955
|
/**
|
|
1927
1956
|
* Creates a virtual type with the given name.
|
|
1928
1957
|
*
|
|
1929
|
-
* @param {String} name
|
|
1958
|
+
* @param {String} name The name of the Virtual
|
|
1930
1959
|
* @param {Object} [options]
|
|
1931
1960
|
* @param {String|Model} [options.ref] model name or model instance. Marks this as a [populate virtual](/docs/populate.html#populate-virtuals).
|
|
1932
1961
|
* @param {String|Function} [options.localField] Required for populate virtuals. See [populate virtual docs](/docs/populate.html#populate-virtuals) for more information.
|
|
@@ -2044,8 +2073,8 @@ Schema.prototype.virtual = function(name, options) {
|
|
|
2044
2073
|
/**
|
|
2045
2074
|
* Returns the virtual type with the given `name`.
|
|
2046
2075
|
*
|
|
2047
|
-
* @param {String} name
|
|
2048
|
-
* @return {VirtualType}
|
|
2076
|
+
* @param {String} name The name of the Virtual to get
|
|
2077
|
+
* @return {VirtualType|null}
|
|
2049
2078
|
*/
|
|
2050
2079
|
|
|
2051
2080
|
Schema.prototype.virtualpath = function(name) {
|
|
@@ -2062,7 +2091,13 @@ Schema.prototype.virtualpath = function(name) {
|
|
|
2062
2091
|
* schema.path('name'); // Undefined
|
|
2063
2092
|
* schema.path('age'); // SchemaNumber { ... }
|
|
2064
2093
|
*
|
|
2065
|
-
*
|
|
2094
|
+
* Or as a Array:
|
|
2095
|
+
*
|
|
2096
|
+
* schema.remove(['name', 'age']);
|
|
2097
|
+
* schema.path('name'); // Undefined
|
|
2098
|
+
* schema.path('age'); // Undefined
|
|
2099
|
+
*
|
|
2100
|
+
* @param {String|Array} path The Path(s) to remove
|
|
2066
2101
|
* @return {Schema} the Schema instance
|
|
2067
2102
|
* @api public
|
|
2068
2103
|
*/
|
|
@@ -2150,7 +2185,7 @@ function _deletePath(schema, name) {
|
|
|
2150
2185
|
* userSchema.loadClass(UserClass);
|
|
2151
2186
|
* ```
|
|
2152
2187
|
*
|
|
2153
|
-
* @param {Function} model
|
|
2188
|
+
* @param {Function} model The Class to load
|
|
2154
2189
|
* @param {Boolean} [virtualsOnly] if truthy, only pulls virtuals from the class, not methods or statics
|
|
2155
2190
|
*/
|
|
2156
2191
|
Schema.prototype.loadClass = function(model, virtualsOnly) {
|
package/lib/schematype.js
CHANGED
|
@@ -206,7 +206,7 @@ SchemaType.prototype.splitPath = function() {
|
|
|
206
206
|
* @param {Function|false} caster Function that casts arbitrary values to this type, or throws an error if casting failed
|
|
207
207
|
* @return {Function}
|
|
208
208
|
* @static
|
|
209
|
-
* @
|
|
209
|
+
* @memberOf SchemaType
|
|
210
210
|
* @function cast
|
|
211
211
|
* @api public
|
|
212
212
|
*/
|
|
@@ -239,9 +239,7 @@ SchemaType.cast = function cast(caster) {
|
|
|
239
239
|
*
|
|
240
240
|
* @param {Function|false} caster Function that casts arbitrary values to this type, or throws an error if casting failed
|
|
241
241
|
* @return {Function}
|
|
242
|
-
* @
|
|
243
|
-
* @receiver SchemaType
|
|
244
|
-
* @function cast
|
|
242
|
+
* @memberOf SchemaType
|
|
245
243
|
* @api public
|
|
246
244
|
*/
|
|
247
245
|
|
|
@@ -279,10 +277,10 @@ SchemaType.prototype.cast = function cast() {
|
|
|
279
277
|
* mongoose.SchemaTypes.String.set('trim', true);
|
|
280
278
|
*
|
|
281
279
|
* @param {String} option The name of the option you'd like to set (e.g. trim, lowercase, etc...)
|
|
282
|
-
* @param {
|
|
280
|
+
* @param {Any} value The value of the option you'd like to set.
|
|
283
281
|
* @return {void}
|
|
284
282
|
* @static
|
|
285
|
-
* @
|
|
283
|
+
* @memberOf SchemaType
|
|
286
284
|
* @function set
|
|
287
285
|
* @api public
|
|
288
286
|
*/
|
|
@@ -305,7 +303,7 @@ SchemaType.set = function set(option, value) {
|
|
|
305
303
|
* @param {Function} getter
|
|
306
304
|
* @return {this}
|
|
307
305
|
* @static
|
|
308
|
-
* @
|
|
306
|
+
* @memberOf SchemaType
|
|
309
307
|
* @function get
|
|
310
308
|
* @api public
|
|
311
309
|
*/
|
|
@@ -384,6 +382,7 @@ SchemaType.prototype.default = function(val) {
|
|
|
384
382
|
* #### Example:
|
|
385
383
|
*
|
|
386
384
|
* const s = new Schema({ name: { type: String, index: true })
|
|
385
|
+
* const s = new Schema({ name: { type: String, index: -1 })
|
|
387
386
|
* const s = new Schema({ loc: { type: [Number], index: 'hashed' })
|
|
388
387
|
* const s = new Schema({ loc: { type: [Number], index: '2d', sparse: true })
|
|
389
388
|
* const s = new Schema({ loc: { type: [Number], index: { type: '2dsphere', sparse: true }})
|
|
@@ -399,7 +398,7 @@ SchemaType.prototype.default = function(val) {
|
|
|
399
398
|
* read/write operations you send until the index build.
|
|
400
399
|
* Specify `background: false` to override Mongoose's default._
|
|
401
400
|
*
|
|
402
|
-
* @param {Object|Boolean|String} options
|
|
401
|
+
* @param {Object|Boolean|String|Number} options
|
|
403
402
|
* @return {SchemaType} this
|
|
404
403
|
* @api public
|
|
405
404
|
*/
|
|
@@ -1243,7 +1242,7 @@ SchemaType.prototype.select = function select(val) {
|
|
|
1243
1242
|
* @param {any} value
|
|
1244
1243
|
* @param {Function} callback
|
|
1245
1244
|
* @param {Object} scope
|
|
1246
|
-
* @api
|
|
1245
|
+
* @api public
|
|
1247
1246
|
*/
|
|
1248
1247
|
|
|
1249
1248
|
SchemaType.prototype.doValidate = function(value, fn, scope, options) {
|
|
@@ -1635,7 +1634,7 @@ SchemaType.prototype._castForQuery = function(val) {
|
|
|
1635
1634
|
* @param {Function} fn
|
|
1636
1635
|
* @return {Function}
|
|
1637
1636
|
* @static
|
|
1638
|
-
* @
|
|
1637
|
+
* @memberOf SchemaType
|
|
1639
1638
|
* @function checkRequired
|
|
1640
1639
|
* @api public
|
|
1641
1640
|
*/
|
|
@@ -35,7 +35,7 @@ const methods = {
|
|
|
35
35
|
*
|
|
36
36
|
* @method _cast
|
|
37
37
|
* @api private
|
|
38
|
-
* @
|
|
38
|
+
* @memberOf MongooseDocumentArray
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
41
|
_cast(value, index) {
|
|
@@ -376,4 +376,4 @@ function _updateParentPopulated(arr) {
|
|
|
376
376
|
|
|
377
377
|
parent.$__.populated[path].value = arr.map(val => val.$populated(remnant));
|
|
378
378
|
}
|
|
379
|
-
}
|
|
379
|
+
}
|
package/lib/types/buffer.js
CHANGED
|
@@ -70,7 +70,8 @@ MongooseBuffer.mixin = {
|
|
|
70
70
|
*
|
|
71
71
|
* @api private
|
|
72
72
|
* @property _subtype
|
|
73
|
-
* @
|
|
73
|
+
* @memberOf MongooseBuffer.mixin
|
|
74
|
+
* @static
|
|
74
75
|
*/
|
|
75
76
|
|
|
76
77
|
_subtype: undefined,
|
|
@@ -80,7 +81,8 @@ MongooseBuffer.mixin = {
|
|
|
80
81
|
*
|
|
81
82
|
* @api private
|
|
82
83
|
* @method _markModified
|
|
83
|
-
* @
|
|
84
|
+
* @memberOf MongooseBuffer.mixin
|
|
85
|
+
* @static
|
|
84
86
|
*/
|
|
85
87
|
|
|
86
88
|
_markModified: function() {
|
|
@@ -97,7 +99,8 @@ MongooseBuffer.mixin = {
|
|
|
97
99
|
*
|
|
98
100
|
* @api public
|
|
99
101
|
* @method write
|
|
100
|
-
* @
|
|
102
|
+
* @memberOf MongooseBuffer.mixin
|
|
103
|
+
* @static
|
|
101
104
|
*/
|
|
102
105
|
|
|
103
106
|
write: function() {
|
|
@@ -120,7 +123,8 @@ MongooseBuffer.mixin = {
|
|
|
120
123
|
* @return {Number} The number of bytes copied.
|
|
121
124
|
* @param {Buffer} target
|
|
122
125
|
* @method copy
|
|
123
|
-
* @
|
|
126
|
+
* @memberOf MongooseBuffer.mixin
|
|
127
|
+
* @static
|
|
124
128
|
*/
|
|
125
129
|
|
|
126
130
|
copy: function(target) {
|
|
@@ -161,24 +165,22 @@ MongooseBuffer.mixin = {
|
|
|
161
165
|
/**
|
|
162
166
|
* Converts this buffer to its Binary type representation.
|
|
163
167
|
*
|
|
164
|
-
* ####SubTypes:
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* doc.buffer.toObject(bson.BSON_BINARY_SUBTYPE_USER_DEFINED);
|
|
168
|
+
* #### SubTypes:
|
|
169
|
+
* const bson = require('bson')
|
|
170
|
+
* bson.BSON_BINARY_SUBTYPE_DEFAULT
|
|
171
|
+
* bson.BSON_BINARY_SUBTYPE_FUNCTION
|
|
172
|
+
* bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
|
|
173
|
+
* bson.BSON_BINARY_SUBTYPE_UUID
|
|
174
|
+
* bson.BSON_BINARY_SUBTYPE_MD5
|
|
175
|
+
* bson.BSON_BINARY_SUBTYPE_USER_DEFINED
|
|
176
|
+
* doc.buffer.toObject(bson.BSON_BINARY_SUBTYPE_USER_DEFINED);
|
|
175
177
|
*
|
|
176
178
|
* @see https://bsonspec.org/#/specification
|
|
177
179
|
* @param {Hex} [subtype]
|
|
178
180
|
* @return {Binary}
|
|
179
181
|
* @api public
|
|
180
182
|
* @method toObject
|
|
181
|
-
* @
|
|
183
|
+
* @memberOf MongooseBuffer
|
|
182
184
|
*/
|
|
183
185
|
|
|
184
186
|
MongooseBuffer.mixin.toObject = function(options) {
|
|
@@ -196,7 +198,7 @@ MongooseBuffer.mixin.$toObject = MongooseBuffer.mixin.toObject;
|
|
|
196
198
|
* @return {Binary}
|
|
197
199
|
* @api public
|
|
198
200
|
* @method toBSON
|
|
199
|
-
* @
|
|
201
|
+
* @memberOf MongooseBuffer
|
|
200
202
|
*/
|
|
201
203
|
|
|
202
204
|
MongooseBuffer.mixin.toBSON = function() {
|
|
@@ -209,7 +211,7 @@ MongooseBuffer.mixin.toBSON = function() {
|
|
|
209
211
|
* @param {Buffer} other
|
|
210
212
|
* @return {Boolean}
|
|
211
213
|
* @method equals
|
|
212
|
-
* @
|
|
214
|
+
* @memberOf MongooseBuffer
|
|
213
215
|
*/
|
|
214
216
|
|
|
215
217
|
MongooseBuffer.mixin.equals = function(other) {
|
|
@@ -233,23 +235,23 @@ MongooseBuffer.mixin.equals = function(other) {
|
|
|
233
235
|
/**
|
|
234
236
|
* Sets the subtype option and marks the buffer modified.
|
|
235
237
|
*
|
|
236
|
-
* ####SubTypes:
|
|
238
|
+
* #### SubTypes:
|
|
237
239
|
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
240
|
+
* const bson = require('bson')
|
|
241
|
+
* bson.BSON_BINARY_SUBTYPE_DEFAULT
|
|
242
|
+
* bson.BSON_BINARY_SUBTYPE_FUNCTION
|
|
243
|
+
* bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
|
|
244
|
+
* bson.BSON_BINARY_SUBTYPE_UUID
|
|
245
|
+
* bson.BSON_BINARY_SUBTYPE_MD5
|
|
246
|
+
* bson.BSON_BINARY_SUBTYPE_USER_DEFINED
|
|
245
247
|
*
|
|
246
|
-
*
|
|
248
|
+
* doc.buffer.subtype(bson.BSON_BINARY_SUBTYPE_UUID);
|
|
247
249
|
*
|
|
248
250
|
* @see https://bsonspec.org/#/specification
|
|
249
251
|
* @param {Hex} subtype
|
|
250
252
|
* @api public
|
|
251
253
|
* @method subtype
|
|
252
|
-
* @
|
|
254
|
+
* @memberOf MongooseBuffer
|
|
253
255
|
*/
|
|
254
256
|
|
|
255
257
|
MongooseBuffer.mixin.subtype = function(subtype) {
|
package/lib/types/decimal128.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Decimal128 type constructor
|
|
3
3
|
*
|
|
4
|
-
* #### Example
|
|
4
|
+
* #### Example:
|
|
5
5
|
*
|
|
6
|
-
* const id = new mongoose.Types.
|
|
6
|
+
* const id = new mongoose.Types.Decimal128('3.1415');
|
|
7
7
|
*
|
|
8
|
-
* @constructor
|
|
8
|
+
* @constructor Decimal128
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|