rap-2-h
rap-2-h

Reputation: 31948

Enum on array with mongoose

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

Answers (1)

JohnnyHK
JohnnyHK

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

Related Questions