Advanced Schemas
Redirecting
Aggregate
AggregationCursor
Array
ArraySubdocument
Buffer
Connection
Decimal128
Document
DocumentArray
Error
Map
Model
Mongoose
Query
QueryCursor
Schema
SchemaArray
SchemaArrayOptions
SchemaBoolean
SchemaBuffer
SchemaBufferOptions
SchemaDateOptions
SchemaDocumentArray
SchemaNumber
SchemaNumberOptions
SchemaObjectId
SchemaObjectIdOptions
SchemaString
SchemaStringOptions
SchemaSubdocument
SchemaType
SchemaType()
SchemaType.cast()
SchemaType.checkRequired()
SchemaType.get()
SchemaType.prototype.cast()
SchemaType.prototype.castFunction()
SchemaType.prototype.default()
SchemaType.prototype.doValidate()
SchemaType.prototype.get()
SchemaType.prototype.immutable()
SchemaType.prototype.index()
SchemaType.prototype.isRequired
SchemaType.prototype.path
SchemaType.prototype.ref()
SchemaType.prototype.required()
SchemaType.prototype.select()
SchemaType.prototype.set()
SchemaType.prototype.sparse()
SchemaType.prototype.text()
SchemaType.prototype.transform()
SchemaType.prototype.unique()
SchemaType.prototype.validate()
SchemaType.prototype.validators
SchemaType.set()
SchemaType()
Parameters:
path
+})();SchemaType()
SchemaType.cast()
SchemaType.checkRequired()
SchemaType.get()
SchemaType.prototype.cast()
SchemaType.prototype.castFunction()
SchemaType.prototype.default()
SchemaType.prototype.doValidate()
SchemaType.prototype.get()
SchemaType.prototype.immutable()
SchemaType.prototype.index()
SchemaType.prototype.isRequired
SchemaType.prototype.path
SchemaType.prototype.ref()
SchemaType.prototype.required()
SchemaType.prototype.select()
SchemaType.prototype.set()
SchemaType.prototype.sparse()
SchemaType.prototype.text()
SchemaType.prototype.transform()
SchemaType.prototype.unique()
SchemaType.prototype.validate()
SchemaType.prototype.validateAll()
SchemaType.prototype.validators
SchemaType.set()
SchemaType()
Parameters:
path
«String»[options]
«SchemaTypeOptions» See SchemaTypeOptions docs[instance]
@@ -330,7 +330,7 @@Example:
Suppose you are implementing user registration for a website. Users provide an email and password, which gets saved to mongodb. The email is a string that you will want to normalize to lower case, in order to avoid one email -having more than one account -- e.g., otherwise, avenue@q.com can be registered for 2 accounts via avenue@q.com and AvEnUe@Q.CoM.
+having more than one account -- e.g., otherwise, avenue@q.com can be registered for 2 accounts via avenue@q.com and AvEnUe@Q.CoM.You can set up email lower case normalization easily via a Mongoose setter.
function toLower(v) { return v.toLowerCase(); @@ -492,7 +492,7 @@
Error message templates:
the validator throws, do this:
@@ -523,6 +523,9 @@schema.path('name').validate({ validator: function() { throw new Error('Oops!'); }, - // `errors['name']` will be "Oops!" + // `errors['name'].message` will be "Oops!" message: function(props) { return props.reason.message; } });
Asynchronous validation:
+// registering an error listener on the Model lets us handle errors more locally Product.on('error', handleError);
SchemaType.prototype.validateAll()
Parameters:
validators
+«Array<RegExp|Function|Object>»
Adds multiple validators for this document path. +Calls
validate()
for every element in validators.SchemaType.prototype.validators
Type:
- «property»
The validators that Mongoose should run to validate properties at this SchemaType's path.
Example:
const schema = new Schema({ name: { type: String, required: true } }); diff --git a/docs/api/schematypeoptions.html b/docs/api/schematypeoptions.html index 48392d2ce47..d0146c1a519 100644 --- a/docs/api/schematypeoptions.html +++ b/docs/api/schematypeoptions.html @@ -1,4 +1,4 @@ -
Mongoose v8.2.4: SchemaTypeOptions