mongoose enumeration for schema code example

Example: 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')],
},

Tags:

Misc Example