1

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?

1 Answer 1

5

Assuming you mean an array of enums, that would be:

const testSchema = new Schema({
    name: String,
    enums: [{type: String, enum: ['Coffee', 'Tea']}]
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you +1! (and sorry about being a bit too vague) Will accept in 3 minutes (I have to wait because SO)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.