Mongoose Enum Number Mongoose Enum Number mongoose mongoose

Mongoose Enum Number


To specify a range of numeric values, you can define min and max values in the schema:

role: {    type: Number,    min: 0,    max: 2,    default: 1},

Docs here.

To also require that the values are integers, see here.


The enums here are basically String objects. They cant be Numbers

  • All SchemaTypes have the built-in required validator.The required validator uses the SchemaType's checkRequired() function to determine if the value satisfies the required validator.

  • Numbers have min and max validators.

  • Strings have enum, match, maxlength and minlength validators.


You can get integer enums in schema.path('some_path').options.enum;as mentioned in Docs here