The other day I saw a comment on the Web somewhere telling one how to access the list of values defined for an Enum field in a Mongoose.js Schema. Sadly, I didn't commit that tidbit or its URL to memory and now I need it!
Does anyone know how to do this?
Thanks in advance!
Is this what you're looking for?
var mongoose = require('./index')
, TempSchema = new mongoose.Schema({
salutation: {type: String, enum: ['Mr.', 'Mrs.', 'Ms.']}
});
var Temp = mongoose.model('Temp', TempSchema);
console.log(Temp.schema.path('salutation').enumValues);
var temp = new Temp();
console.log(temp.schema.path('salutation').enumValues);
Source: https://gist.github.com/953059
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With