key «String» cast «SchemaType» options «Object» schemaOptions «Object» Array SchemaType constructor
fn «Function» Override the function the required validator uses to check whether an array passes the required check.
// Require non-empty array to pass `required` check
mongoose.Schema.Types.Array.checkRequired(v => Array.isArray(v) && v.length);
const M = mongoose.model({ arr: { type: Array, required: true } });
new M({ arr: [] }).validateSync(); // `null`, validation fails!
getter «Function» Attaches a getter for all Array instances
Options for all arrays.
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.value «Any» doc «Document» Check if the given value satisfies the required validator.
[...args] «String|Object» enumeration values Adds an enum validator if this is an array of strings or numbers. Equivalent to SchemaString.prototype.enum() or SchemaNumber.prototype.enum()
This schema type's name, to defend against minifiers that mangle function names.
option «String» The option you'd like to set the value for value «Any» value for option Sets a default option for all Array instances.
// Make all Array instances have `required` of true by default.
mongoose.Schema.Array.set('required', true);
const User = mongoose.model('User', new Schema({ test: Array }));
new User({ }).validateSync().errors.test.message; // Path `test` is required.
© 2010 LearnBoost
Licensed under the MIT License.
https://mongoosejs.com/docs/api/schemaarray.html