Property | Type | Accepts | Description |
required | any | boolean, function | If true, adds a required validator for this property. |
default | any | any | Sets a default value for the path. If the value is a function, the return value of the function is used as the default. |
select | any | boolean | Specifies default projections for queries. |
validate | any | function | Adds a validator function for this property. |
get | any | function | Defines a custom getter for this property using Object.defineProperty() |
set | any | function | Defines a custom setter for this property using Object.defineProperty() |
alias | any | string | Defines a virtual with the given name that gets/sets this path. |
index | any | boolean | Whether to define a index on this property. |
unique | any | boolean | Whether to define a unique index on this property. |
sparse | any | boolean | Whether to define a sparse index on this property. |
lowercase | string | boolean | Whether to always call .toLowerCase() on the value. |
uppercase | string | boolean | Whether to always call .toUpperCase() on the value. |
trim | string | boolean | Whether to always call .trim() on the value. |
match | string | regular expression | Creates a validator that checks whether the value matches the given regular expression. |
enum | string | array | Creates a validator that checks whether the value is in the given array. |
maxlength | string | number | Specifies a maximum character length on this property. |
minlength | string | number | Specifies a minimum character length on this property. |
max | date, number | date, number | Specifies a maximum date or number on this property. |
min | date, number | date, number | Specifies a minimum date or number on this property. |
expires | date | date |
Specifies an expiration date on this property. |
To learn more about the schema API in Mongoose, you can check out the official documentation page: