Access the list of valid values ​​for the Enum field in the Mongoose.js schema

The other day I saw a comment on the Internet somewhere telling about how to access the list of values ​​defined for the Enum field in the Mongoose.js schema. Unfortunately, I did not pass this tidbit or its URL into memory, and now I need it!

Does anyone know how to do this?

Thanks in advance!

+4
source share
1 answer

Is this what you are 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

+17
source

Source: https://habr.com/ru/post/1413035/


All Articles