Reputation: 31948
According to the documentation (https://mongoosejs.com/docs/validation.html#built-in-validators):
Strings have enum, match, maxlength and minlength validators.
(the link does point to an invalid zone of the doc).
Is there a way to declare enum on array with mongoose?
Upvotes: 1
Views: 1785
Reputation: 311865
Assuming you mean an array of enums, that would be:
const testSchema = new Schema({
name: String,
enums: [{type: String, enum: ['Coffee', 'Tea']}]
});
Upvotes: 5