enum mongoose example

Example 1: mongoose schema enum example

let inventory_type_enum = ["goods", "services"];

 inventory_type: {
    type: String,
    enum: inventory_type_enum,
    validate: {
      //  validator: (inventory_type) => !inventory_type.enum.includes(inventory_type),
        validator: (inventory_type) => inventory_type_enum.includes(inventory_type),
        message: languages('general_merchandise_model','inventory_type')
    },
      required : [true, languages('general_merchandise_model','inventory_type_required')],
},

Example 2: mongoose model enum

enum Role {
  ADMIN = 'ADMIN',
  USER = 'USER'
}

{
    type: String,
    enum: Role,
    default: Role.USER,
}

Tags:

Misc Example