mongoose 9.2.3 → 9.2.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/lib/aggregate.js +41 -41
- package/lib/cast/bigint.js +2 -2
- package/lib/cast/boolean.js +3 -3
- package/lib/cast/double.js +2 -2
- package/lib/cast/int32.js +2 -2
- package/lib/cast/number.js +2 -2
- package/lib/cast/string.js +2 -2
- package/lib/cast.js +6 -6
- package/lib/collection.js +4 -4
- package/lib/connection.js +58 -58
- package/lib/cursor/aggregationCursor.js +6 -6
- package/lib/cursor/queryCursor.js +7 -7
- package/lib/document.js +176 -176
- package/lib/drivers/node-mongodb-native/collection.js +2 -2
- package/lib/drivers/node-mongodb-native/connection.js +8 -8
- package/lib/error/cast.js +2 -2
- package/lib/error/createCollectionsError.js +2 -2
- package/lib/error/divergentArray.js +1 -1
- package/lib/error/eachAsyncMultiError.js +1 -1
- package/lib/error/index.js +2 -2
- package/lib/error/invalidSchemaOption.js +1 -1
- package/lib/error/missingSchema.js +1 -1
- package/lib/error/objectParameter.js +3 -3
- package/lib/error/overwriteModel.js +1 -1
- package/lib/error/setOptionError.js +3 -3
- package/lib/error/strict.js +3 -3
- package/lib/error/strictPopulate.js +2 -2
- package/lib/error/syncIndexes.js +2 -2
- package/lib/error/validation.js +2 -2
- package/lib/error/validator.js +1 -1
- package/lib/error/version.js +2 -2
- package/lib/helpers/buildMiddlewareFilter.js +2 -2
- package/lib/helpers/clone.js +4 -4
- package/lib/helpers/createJSONSchemaTypeDefinition.js +4 -4
- package/lib/helpers/cursor/eachAsync.js +3 -3
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +3 -3
- package/lib/helpers/document/applyTimestamps.js +9 -9
- package/lib/helpers/document/applyVirtuals.js +6 -6
- package/lib/helpers/document/compile.js +10 -10
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +2 -2
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
- package/lib/helpers/indexes/isIndexEqual.js +3 -3
- package/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +2 -2
- package/lib/helpers/isSimpleValidator.js +2 -2
- package/lib/helpers/minimize.js +2 -2
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/castBulkWrite.js +2 -2
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +2 -2
- package/lib/helpers/populate/assignVals.js +6 -6
- package/lib/helpers/populate/createPopulateQueryFilter.js +2 -2
- package/lib/helpers/populate/getModelsMapForPopulate.js +12 -12
- package/lib/helpers/populate/getSchemaTypes.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -3
- package/lib/helpers/projection/isSubpath.js +1 -1
- package/lib/helpers/query/castUpdate.js +14 -14
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +4 -4
- package/lib/helpers/query/handleImmutable.js +6 -6
- package/lib/helpers/schema/getIndexes.js +1 -1
- package/lib/helpers/schema/getSubdocumentStrictValue.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +3 -3
- package/lib/helpers/update/modifiedPaths.js +2 -2
- package/lib/helpers/updateValidators.js +2 -2
- package/lib/model.js +263 -263
- package/lib/mongoose.js +54 -54
- package/lib/options/schemaArrayOptions.js +2 -2
- package/lib/options/schemaBufferOptions.js +1 -1
- package/lib/options/schemaNumberOptions.js +3 -3
- package/lib/options/schemaObjectIdOptions.js +2 -2
- package/lib/options/schemaStringOptions.js +6 -6
- package/lib/options/schemaTypeOptions.js +13 -13
- package/lib/options/virtualOptions.js +11 -11
- package/lib/query.js +222 -222
- package/lib/queryHelpers.js +4 -4
- package/lib/schema/array.js +18 -18
- package/lib/schema/bigint.js +13 -13
- package/lib/schema/boolean.js +13 -13
- package/lib/schema/buffer.js +14 -14
- package/lib/schema/date.js +16 -16
- package/lib/schema/decimal128.js +13 -13
- package/lib/schema/documentArray.js +15 -15
- package/lib/schema/documentArrayElement.js +5 -6
- package/lib/schema/double.js +12 -12
- package/lib/schema/int32.js +13 -13
- package/lib/schema/map.js +10 -10
- package/lib/schema/mixed.js +10 -10
- package/lib/schema/number.js +18 -18
- package/lib/schema/objectId.js +14 -14
- package/lib/schema/operators/text.js +3 -3
- package/lib/schema/string.js +17 -17
- package/lib/schema/subdocument.js +13 -13
- package/lib/schema/union.js +3 -3
- package/lib/schema/uuid.js +16 -16
- package/lib/schema.js +76 -76
- package/lib/schemaType.js +62 -62
- package/lib/stateMachine.js +5 -8
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +12 -12
- package/lib/types/arraySubdocument.js +8 -8
- package/lib/types/buffer.js +4 -4
- package/lib/types/documentArray/index.js +1 -1
- package/lib/types/documentArray/methods/index.js +5 -5
- package/lib/types/map.js +3 -3
- package/lib/types/subdocument.js +11 -11
- package/lib/utils.js +45 -45
- package/lib/virtualType.js +18 -18
- package/package.json +8 -5
- package/types/index.d.ts +16 -15
- package/types/inferschematype.d.ts +10 -0
- package/types/models.d.ts +7 -4
- package/types/schemaoptions.d.ts +1 -1
- package/types/virtuals.d.ts +10 -10
package/lib/schema.js
CHANGED
|
@@ -98,8 +98,8 @@ const numberRE = /^\d+$/;
|
|
|
98
98
|
*
|
|
99
99
|
* _When nesting schemas, (`children` in the example above), always declare the child schema first before passing it into its parent._
|
|
100
100
|
*
|
|
101
|
-
* @param {
|
|
102
|
-
* @param {
|
|
101
|
+
* @param {object|Schema|Array} [definition] Can be one of: object describing schema paths, or schema to copy, or array of objects and schemas
|
|
102
|
+
* @param {object} [options]
|
|
103
103
|
* @inherits NodeJS EventEmitter https://nodejs.org/api/events.html#class-eventemitter
|
|
104
104
|
* @event `init`: Emitted after the schema is compiled into a `Model`.
|
|
105
105
|
* @api public
|
|
@@ -385,8 +385,8 @@ Schema.prototype.tree;
|
|
|
385
385
|
* // Equivalent:
|
|
386
386
|
* const schema2 = new Schema({ name: String }, { toObject: { virtuals: true } });
|
|
387
387
|
*
|
|
388
|
-
* @param {
|
|
389
|
-
* @param {
|
|
388
|
+
* @param {object} definition
|
|
389
|
+
* @param {object} [options]
|
|
390
390
|
* @return {Schema} the new schema
|
|
391
391
|
* @api public
|
|
392
392
|
* @memberOf Schema
|
|
@@ -510,8 +510,8 @@ Schema.prototype._clone = function _clone(Constructor) {
|
|
|
510
510
|
* newSchema.path('name'); // SchemaString { ... }
|
|
511
511
|
* newSchema.path('age'); // undefined
|
|
512
512
|
*
|
|
513
|
-
* @param {
|
|
514
|
-
* @param {
|
|
513
|
+
* @param {string[]} paths List of Paths to pick for the new Schema
|
|
514
|
+
* @param {object} [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`). Defaults to `this.options` if not set.
|
|
515
515
|
* @return {Schema}
|
|
516
516
|
* @api public
|
|
517
517
|
*/
|
|
@@ -565,8 +565,8 @@ Schema.prototype.pick = function(paths, options) {
|
|
|
565
565
|
* newSchema.path('name'); // SchemaString { ... }
|
|
566
566
|
* newSchema.path('age'); // undefined
|
|
567
567
|
*
|
|
568
|
-
* @param {
|
|
569
|
-
* @param {
|
|
568
|
+
* @param {string[]} paths List of Paths to omit for the new Schema
|
|
569
|
+
* @param {object} [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`). Defaults to `this.options` if not set.
|
|
570
570
|
* @return {Schema}
|
|
571
571
|
* @api public
|
|
572
572
|
*/
|
|
@@ -596,8 +596,8 @@ Schema.prototype.omit = function(paths, options) {
|
|
|
596
596
|
/**
|
|
597
597
|
* Returns default options for this schema, merged with `options`.
|
|
598
598
|
*
|
|
599
|
-
* @param {
|
|
600
|
-
* @return {
|
|
599
|
+
* @param {object} [options] Options to overwrite the default options
|
|
600
|
+
* @return {object} The merged options of `options` and the default options
|
|
601
601
|
* @api private
|
|
602
602
|
*/
|
|
603
603
|
|
|
@@ -672,14 +672,14 @@ Schema.prototype.defaultOptions = function(options) {
|
|
|
672
672
|
* doc.element; // '#hero'
|
|
673
673
|
* doc instanceof ClickedModel; // true
|
|
674
674
|
*
|
|
675
|
-
* @param {
|
|
675
|
+
* @param {string} name the name of the discriminator
|
|
676
676
|
* @param {Schema} schema the discriminated Schema
|
|
677
|
-
* @param {
|
|
678
|
-
* @param {
|
|
679
|
-
* @param {
|
|
680
|
-
* @param {
|
|
681
|
-
* @param {
|
|
682
|
-
* @param {
|
|
677
|
+
* @param {object} [options] discriminator options
|
|
678
|
+
* @param {string} [options.value] the string stored in the `discriminatorKey` property. If not specified, Mongoose uses the `name` parameter.
|
|
679
|
+
* @param {boolean} [options.clone=true] By default, `discriminator()` clones the given `schema`. Set to `false` to skip cloning.
|
|
680
|
+
* @param {boolean} [options.overwriteModels=false] by default, Mongoose does not allow you to define a discriminator with the same name as another discriminator. Set this to allow overwriting discriminators with the same name.
|
|
681
|
+
* @param {boolean} [options.mergeHooks=true] By default, Mongoose merges the base schema's hooks with the discriminator schema's hooks. Set this option to `false` to make Mongoose use the discriminator schema's hooks instead.
|
|
682
|
+
* @param {boolean} [options.mergePlugins=true] By default, Mongoose merges the base schema's plugins with the discriminator schema's plugins. Set this option to `false` to make Mongoose use the discriminator schema's plugins instead.
|
|
683
683
|
* @return {Schema} the Schema instance
|
|
684
684
|
* @api public
|
|
685
685
|
*/
|
|
@@ -768,8 +768,8 @@ Schema.prototype.encryptionType = function encryptionType(encryptionType) {
|
|
|
768
768
|
* // getters, setters, indexes, methods, and statics.
|
|
769
769
|
* TurboManSchema.add(ToySchema).add({ year: Number });
|
|
770
770
|
*
|
|
771
|
-
* @param {
|
|
772
|
-
* @param {
|
|
771
|
+
* @param {object|Schema} obj plain object with paths to add, or another schema
|
|
772
|
+
* @param {string} [prefix] path to prefix the newly added paths with
|
|
773
773
|
* @return {Schema} the Schema instance
|
|
774
774
|
* @api public
|
|
775
775
|
*/
|
|
@@ -1073,8 +1073,8 @@ Schema.prototype._buildSchemaMap = function() {
|
|
|
1073
1073
|
* await turboMan.save(); // Saves { _id: ..., n: 'Turbo Man Action Figure' }
|
|
1074
1074
|
*
|
|
1075
1075
|
*
|
|
1076
|
-
* @param {
|
|
1077
|
-
* @param {
|
|
1076
|
+
* @param {string} path real path to alias
|
|
1077
|
+
* @param {string|string[]} alias the path(s) to use as an alias for `path`
|
|
1078
1078
|
* @return {Schema} the Schema instance
|
|
1079
1079
|
* @api public
|
|
1080
1080
|
*/
|
|
@@ -1106,7 +1106,7 @@ Schema.prototype.alias = function alias(path, alias) {
|
|
|
1106
1106
|
* // Remove index by name
|
|
1107
1107
|
* ToySchema.removeIndex('my custom index name');
|
|
1108
1108
|
*
|
|
1109
|
-
* @param {
|
|
1109
|
+
* @param {object|string} index name or index specification
|
|
1110
1110
|
* @return {Schema} the Schema instance
|
|
1111
1111
|
* @api public
|
|
1112
1112
|
*/
|
|
@@ -1173,9 +1173,9 @@ Schema.prototype.clearIndexes = function clearIndexes() {
|
|
|
1173
1173
|
* const ToySchema = new Schema({ name: String, color: String, price: Number });
|
|
1174
1174
|
* ToySchema.searchIndex({ name: 'test', definition: { mappings: { dynamic: true } } });
|
|
1175
1175
|
*
|
|
1176
|
-
* @param {
|
|
1177
|
-
* @param {
|
|
1178
|
-
* @param {
|
|
1176
|
+
* @param {object} description index options, including `name` and `definition`
|
|
1177
|
+
* @param {string} description.name
|
|
1178
|
+
* @param {object} description.definition
|
|
1179
1179
|
* @return {Schema} the Schema instance
|
|
1180
1180
|
* @api public
|
|
1181
1181
|
*/
|
|
@@ -1261,8 +1261,8 @@ reserved.collection = 1;
|
|
|
1261
1261
|
* schema.path('name') // returns a SchemaType
|
|
1262
1262
|
* schema.path('name', Number) // changes the schemaType of `name` to Number
|
|
1263
1263
|
*
|
|
1264
|
-
* @param {
|
|
1265
|
-
* @param {
|
|
1264
|
+
* @param {string} path The name of the Path to get / set
|
|
1265
|
+
* @param {object} [obj] The Type to set the path to, if provided the path will be SET, otherwise the path will be GET
|
|
1266
1266
|
* @api public
|
|
1267
1267
|
*/
|
|
1268
1268
|
|
|
@@ -1571,9 +1571,9 @@ Object.defineProperty(Schema.prototype, 'base', {
|
|
|
1571
1571
|
/**
|
|
1572
1572
|
* Converts type arguments into Mongoose Types.
|
|
1573
1573
|
*
|
|
1574
|
-
* @param {
|
|
1575
|
-
* @param {
|
|
1576
|
-
* @param {
|
|
1574
|
+
* @param {string} path
|
|
1575
|
+
* @param {object} obj constructor
|
|
1576
|
+
* @param {object} options schema options
|
|
1577
1577
|
* @api private
|
|
1578
1578
|
*/
|
|
1579
1579
|
|
|
@@ -1840,7 +1840,7 @@ Schema.prototype.eachPath = function(fn) {
|
|
|
1840
1840
|
* s.requiredPaths(); // [ 'age', 'name' ]
|
|
1841
1841
|
*
|
|
1842
1842
|
* @api public
|
|
1843
|
-
* @param {
|
|
1843
|
+
* @param {boolean} invalidate Refresh the cache
|
|
1844
1844
|
* @return {Array}
|
|
1845
1845
|
*/
|
|
1846
1846
|
|
|
@@ -1892,8 +1892,8 @@ Schema.prototype.indexedPaths = function indexedPaths() {
|
|
|
1892
1892
|
* s.pathType('foo'); // "virtual"
|
|
1893
1893
|
* s.pathType('fail'); // "adhocOrUndefined"
|
|
1894
1894
|
*
|
|
1895
|
-
* @param {
|
|
1896
|
-
* @return {
|
|
1895
|
+
* @param {string} path
|
|
1896
|
+
* @return {string}
|
|
1897
1897
|
* @api public
|
|
1898
1898
|
*/
|
|
1899
1899
|
|
|
@@ -1935,8 +1935,8 @@ Schema.prototype.pathType = function(path) {
|
|
|
1935
1935
|
/**
|
|
1936
1936
|
* Returns true iff this path is a child of a mixed schema.
|
|
1937
1937
|
*
|
|
1938
|
-
* @param {
|
|
1939
|
-
* @return {
|
|
1938
|
+
* @param {string} path
|
|
1939
|
+
* @return {boolean}
|
|
1940
1940
|
* @api private
|
|
1941
1941
|
*/
|
|
1942
1942
|
|
|
@@ -1957,7 +1957,7 @@ Schema.prototype.hasMixedParent = function(path) {
|
|
|
1957
1957
|
/**
|
|
1958
1958
|
* Setup updatedAt and createdAt timestamps to documents if enabled
|
|
1959
1959
|
*
|
|
1960
|
-
* @param {
|
|
1960
|
+
* @param {boolean|object} timestamps timestamps options
|
|
1961
1961
|
* @api private
|
|
1962
1962
|
*/
|
|
1963
1963
|
Schema.prototype.setupTimestamp = function(timestamps) {
|
|
@@ -1966,8 +1966,8 @@ Schema.prototype.setupTimestamp = function(timestamps) {
|
|
|
1966
1966
|
|
|
1967
1967
|
/**
|
|
1968
1968
|
* ignore. Deprecated re: #6405
|
|
1969
|
-
* @param {
|
|
1970
|
-
* @param {
|
|
1969
|
+
* @param {any} self
|
|
1970
|
+
* @param {string} path
|
|
1971
1971
|
* @api private
|
|
1972
1972
|
*/
|
|
1973
1973
|
|
|
@@ -2053,7 +2053,7 @@ function getPositionalPath(self, path, cleanPath) {
|
|
|
2053
2053
|
* const Model = mongoose.model('Test', schema);
|
|
2054
2054
|
* new Model({ name: 'test' }); // Prints '{"_id": ..., "name": "test" }'
|
|
2055
2055
|
*
|
|
2056
|
-
* @param {
|
|
2056
|
+
* @param {string} name name of the document method to call later
|
|
2057
2057
|
* @param {Array} args arguments to pass to the method
|
|
2058
2058
|
* @api public
|
|
2059
2059
|
*/
|
|
@@ -2096,10 +2096,10 @@ Schema.prototype.queue = function(name, args) {
|
|
|
2096
2096
|
* // Runs when you call `doc.deleteOne()`
|
|
2097
2097
|
* });
|
|
2098
2098
|
*
|
|
2099
|
-
* @param {
|
|
2100
|
-
* @param {
|
|
2101
|
-
* @param {
|
|
2102
|
-
* @param {
|
|
2099
|
+
* @param {string|RegExp|string[]} methodName The method name or regular expression to match method name
|
|
2100
|
+
* @param {object} [options]
|
|
2101
|
+
* @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()`.
|
|
2102
|
+
* @param {boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
|
|
2103
2103
|
* @param {Function} callback
|
|
2104
2104
|
* @api public
|
|
2105
2105
|
*/
|
|
@@ -2150,10 +2150,10 @@ Schema.prototype.pre = function(name) {
|
|
|
2150
2150
|
* await m.find();
|
|
2151
2151
|
* console.log('this fires after the post find hook');
|
|
2152
2152
|
*
|
|
2153
|
-
* @param {
|
|
2154
|
-
* @param {
|
|
2155
|
-
* @param {
|
|
2156
|
-
* @param {
|
|
2153
|
+
* @param {string|RegExp|string[]} methodName The method name or regular expression to match method name
|
|
2154
|
+
* @param {object} [options]
|
|
2155
|
+
* @param {boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware.
|
|
2156
|
+
* @param {boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
|
|
2157
2157
|
* @param {Function} fn callback
|
|
2158
2158
|
* @see middleware https://mongoosejs.com/docs/middleware.html
|
|
2159
2159
|
* @see kareem https://npmjs.org/package/kareem
|
|
@@ -2197,8 +2197,8 @@ Schema.prototype.post = function(name) {
|
|
|
2197
2197
|
* mongoose.model('Test', s); // Prints 'Schema Path Name: name'
|
|
2198
2198
|
*
|
|
2199
2199
|
* @param {Function} plugin The Plugin's callback
|
|
2200
|
-
* @param {
|
|
2201
|
-
* @param {
|
|
2200
|
+
* @param {object} [opts] Options to pass to the plugin
|
|
2201
|
+
* @param {boolean} [opts.deduplicate=false] If true, ignore duplicate plugins (same `fn` argument using `===`)
|
|
2202
2202
|
* @see plugins https://mongoosejs.com/docs/plugins.html
|
|
2203
2203
|
* @api public
|
|
2204
2204
|
*/
|
|
@@ -2253,7 +2253,7 @@ Schema.prototype.plugin = function(fn, opts) {
|
|
|
2253
2253
|
*
|
|
2254
2254
|
* 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](https://mongoosejs.com/docs/guide.html#methods)
|
|
2255
2255
|
*
|
|
2256
|
-
* @param {
|
|
2256
|
+
* @param {string|object} name The Method Name for a single function, or a Object of "string-function" pairs.
|
|
2257
2257
|
* @param {Function} [fn] The Function in a single-function definition.
|
|
2258
2258
|
* @api public
|
|
2259
2259
|
*/
|
|
@@ -2298,7 +2298,7 @@ Schema.prototype.method = function(name, fn, options) {
|
|
|
2298
2298
|
*
|
|
2299
2299
|
* If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as statics.
|
|
2300
2300
|
*
|
|
2301
|
-
* @param {
|
|
2301
|
+
* @param {string|object} name The Method Name for a single function, or a Object of "string-function" pairs.
|
|
2302
2302
|
* @param {Function} [fn] The Function in a single-function definition.
|
|
2303
2303
|
* @api public
|
|
2304
2304
|
* @see Statics https://mongoosejs.com/docs/guide.html#statics
|
|
@@ -2322,10 +2322,10 @@ Schema.prototype.static = function(name, fn) {
|
|
|
2322
2322
|
*
|
|
2323
2323
|
* schema.index({ first: 1, last: -1 })
|
|
2324
2324
|
*
|
|
2325
|
-
* @param {
|
|
2326
|
-
* @param {
|
|
2327
|
-
* @param {
|
|
2328
|
-
* @param {
|
|
2325
|
+
* @param {object} fields The Fields to index, with the order, available values: `1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text'`
|
|
2326
|
+
* @param {object} [options] Options to pass to [MongoDB driver's `createIndex()` function](https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#createIndex)
|
|
2327
|
+
* @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.
|
|
2328
|
+
* @param {string} [options.language_override=null] Tells mongodb to use the specified field instead of `language` for parsing text indexes.
|
|
2329
2329
|
* @api public
|
|
2330
2330
|
*/
|
|
2331
2331
|
|
|
@@ -2362,9 +2362,9 @@ Schema.prototype.index = function(fields, options) {
|
|
|
2362
2362
|
* schema.set('strict', false); // Sets 'strict' to false
|
|
2363
2363
|
* schema.set('strict'); // 'false'
|
|
2364
2364
|
*
|
|
2365
|
-
* @param {
|
|
2366
|
-
* @param {
|
|
2367
|
-
* @param {
|
|
2365
|
+
* @param {string} key The name of the option to set the value to
|
|
2366
|
+
* @param {object} [value] The value to set the option to, if not passed, the option will be reset to default
|
|
2367
|
+
* @param {string[]} [tags] tags to add to read preference if key === 'read'
|
|
2368
2368
|
* @see Schema https://mongoosejs.com/docs/api/schema.html#Schema()
|
|
2369
2369
|
* @api public
|
|
2370
2370
|
*/
|
|
@@ -2455,9 +2455,9 @@ function _propagateOptionsToImplicitlyCreatedSchemas(baseSchema, options) {
|
|
|
2455
2455
|
* schema.set('strict', false);
|
|
2456
2456
|
* schema.get('strict'); // false
|
|
2457
2457
|
*
|
|
2458
|
-
* @param {
|
|
2458
|
+
* @param {string} key The name of the Option to get the current value for
|
|
2459
2459
|
* @api public
|
|
2460
|
-
* @return {
|
|
2460
|
+
* @return {any} the option's value
|
|
2461
2461
|
*/
|
|
2462
2462
|
|
|
2463
2463
|
Schema.prototype.get = function(key) {
|
|
@@ -2469,7 +2469,7 @@ const indexTypes = '2d 2dsphere hashed text'.split(' ');
|
|
|
2469
2469
|
/**
|
|
2470
2470
|
* The allowed index types
|
|
2471
2471
|
*
|
|
2472
|
-
* @property {
|
|
2472
|
+
* @property {string[]} indexTypes
|
|
2473
2473
|
* @memberOf Schema
|
|
2474
2474
|
* @static
|
|
2475
2475
|
* @api public
|
|
@@ -2521,16 +2521,16 @@ Schema.prototype.indexes = function() {
|
|
|
2521
2521
|
/**
|
|
2522
2522
|
* Creates a virtual type with the given name.
|
|
2523
2523
|
*
|
|
2524
|
-
* @param {
|
|
2525
|
-
* @param {
|
|
2526
|
-
* @param {
|
|
2527
|
-
* @param {
|
|
2528
|
-
* @param {
|
|
2529
|
-
* @param {
|
|
2530
|
-
* @param {
|
|
2524
|
+
* @param {string} name The name of the Virtual
|
|
2525
|
+
* @param {object} [options]
|
|
2526
|
+
* @param {string|Model} [options.ref] model name or model instance. Marks this as a [populate virtual](https://mongoosejs.com/docs/populate.html#populate-virtuals).
|
|
2527
|
+
* @param {string|Function} [options.localField] Required for populate virtuals. See [populate virtual docs](https://mongoosejs.com/docs/populate.html#populate-virtuals) for more information.
|
|
2528
|
+
* @param {string|Function} [options.foreignField] Required for populate virtuals. See [populate virtual docs](https://mongoosejs.com/docs/populate.html#populate-virtuals) for more information.
|
|
2529
|
+
* @param {boolean|Function} [options.justOne=false] Only works with populate virtuals. If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), will be a single doc or `null`. Otherwise, the populate virtual will be an array.
|
|
2530
|
+
* @param {boolean} [options.count=false] Only works with populate virtuals. If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), this populate virtual will contain the number of documents rather than the documents themselves when you `populate()`.
|
|
2531
2531
|
* @param {Function|null} [options.get=null] Adds a [getter](https://mongoosejs.com/docs/tutorials/getters-setters.html) to this virtual to transform the populated doc.
|
|
2532
|
-
* @param {
|
|
2533
|
-
* @param {
|
|
2532
|
+
* @param {object|Function} [options.match=null] Apply a default [`match` option to populate](https://mongoosejs.com/docs/populate.html#match), adding an additional filter to the populate query.
|
|
2533
|
+
* @param {boolean} [options.applyToArray=false] If true and the given `name` is a direct child of an array, apply the virtual to the array rather than the elements.
|
|
2534
2534
|
* @return {VirtualType}
|
|
2535
2535
|
*/
|
|
2536
2536
|
|
|
@@ -2668,7 +2668,7 @@ Schema.prototype.virtual = function(name, options) {
|
|
|
2668
2668
|
/**
|
|
2669
2669
|
* Returns the virtual type with the given `name`.
|
|
2670
2670
|
*
|
|
2671
|
-
* @param {
|
|
2671
|
+
* @param {string} name The name of the Virtual to get
|
|
2672
2672
|
* @return {VirtualType|null}
|
|
2673
2673
|
*/
|
|
2674
2674
|
|
|
@@ -2692,7 +2692,7 @@ Schema.prototype.virtualpath = function(name) {
|
|
|
2692
2692
|
* schema.path('name'); // Undefined
|
|
2693
2693
|
* schema.path('age'); // Undefined
|
|
2694
2694
|
*
|
|
2695
|
-
* @param {
|
|
2695
|
+
* @param {string|Array} path The Path(s) to remove
|
|
2696
2696
|
* @return {Schema} the Schema instance
|
|
2697
2697
|
* @api public
|
|
2698
2698
|
*/
|
|
@@ -2750,7 +2750,7 @@ function _deletePath(schema, name) {
|
|
|
2750
2750
|
/**
|
|
2751
2751
|
* Removes the given virtual or virtuals from the schema.
|
|
2752
2752
|
*
|
|
2753
|
-
* @param {
|
|
2753
|
+
* @param {string|Array} path The virutal path(s) to remove.
|
|
2754
2754
|
* @returns {Schema} the Schema instance, or a mongoose error if the virtual does not exist.
|
|
2755
2755
|
* @api public
|
|
2756
2756
|
*/
|
|
@@ -2815,7 +2815,7 @@ Schema.prototype.removeVirtual = function(path) {
|
|
|
2815
2815
|
* ```
|
|
2816
2816
|
*
|
|
2817
2817
|
* @param {Function} model The Class to load
|
|
2818
|
-
* @param {
|
|
2818
|
+
* @param {boolean} [virtualsOnly] if truthy, only pulls virtuals from the class, not methods or statics
|
|
2819
2819
|
*/
|
|
2820
2820
|
Schema.prototype.loadClass = function(model, virtualsOnly) {
|
|
2821
2821
|
// Stop copying when hit certain base classes
|
|
@@ -3109,8 +3109,8 @@ Schema.prototype._preCompile = function _preCompile() {
|
|
|
3109
3109
|
* // { required: ['_id'], properties: { name: { bsonType: ['string', 'null'] }, _id: { bsonType: 'objectId' } } }
|
|
3110
3110
|
* schema.toJSONSchema({ useBsonType: true });
|
|
3111
3111
|
*
|
|
3112
|
-
* @param {
|
|
3113
|
-
* @param
|
|
3112
|
+
* @param {object} [options]
|
|
3113
|
+
* @param {boolean} [options.useBsonType=false] if true, specify each path's type using `bsonType` rather than `type` for MongoDB $jsonSchema support
|
|
3114
3114
|
*/
|
|
3115
3115
|
|
|
3116
3116
|
Schema.prototype.toJSONSchema = function toJSONSchema(options) {
|