How to get enum values from mongoose schema using virtual method? How to get enum values from mongoose schema using virtual method? mongoose mongoose

How to get enum values from mongoose schema using virtual method?


This is clean and easy way.

var possibleRoles = ['user', 'admin'];var UserSchema = new Schema({    roles: {        type: [{type: String, enum: possibleRoles}],        default: ['user']    }});UserSchema.virtual('possibleRoles').get(function () {    return possibleRoles;});


remove the caster part, i don't know why that is there: return this.schema.path('roles').enumValues;that should work without any other issues