Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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);
var temp = new Temp();

wavded commented May 3, 2011


thanks!!! :)


atishn commented Jul 24, 2013


So neat, but doesn't work for me (mongoose 3.6.20): for the path() function, my enum fields must be prefixed with ".enum", and there is no "enumValues" property on the returned object. This works for me... console.log(Temp.schema.path('salutation.enum').options.type) // We get ['Mr.', 'Mrs.', 'Ms.']

Update: bnoguchi's neater version works if you do Temp.path("salutation").enum('Mr.', 'Mrs.', 'Ms.'); after you've defined the schema (i was using salutation: {enum: ['Mr.', 'Mrs.', 'Ms.']} in the Schema constructor parameter, which doesn't seem to work as well).

I've salutation sub-document inside profile document, so Temp.schema.path('profile.salutation').enumValues works in my case.

m4grio commented Jan 6, 2015



This was very helpful. Thanks

Thanks a lot, helpful!!

Thank you

If you want to know all the enum values inside in array type, you need something like this:


zamrokk commented Sep 7, 2016

👍 This kind of thing is possible too :


chipro commented Jan 15, 2017

Wow, I was just wondering how to do this as I need the enum data to implement a droplist. Very helpful, thanks!

HasanSa commented Mar 29, 2017


LukeXF commented Nov 5, 2017

Perfect, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment