Skip to content

Instantly share code, notes, and snippets.

@hereisfahad
Forked from bnoguchi/enum-access.js
Created March 29, 2020 19:37
Show Gist options
  • Save hereisfahad/05a265e76b103e10ddb4a4841f3a2590 to your computer and use it in GitHub Desktop.
Save hereisfahad/05a265e76b103e10ddb4a4841f3a2590 to your computer and use it in GitHub Desktop.
How to access enumValues in mongoose from a Model or Document
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment