访问Mongoose.js模式中Enum字段的有效值列表 [英] Access the list of valid values for an Enum field in a Mongoose.js Schema
本文介绍了访问Mongoose.js模式中Enum字段的有效值列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
前几天,我在网上的某处看到一条评论,告诉人们如何访问为Mongoose.js模式中的Enum字段定义的值列表.可悲的是,我没有将那个花絮或其URL提交到内存中,现在我需要它!
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!
有人知道该怎么做吗?
提前谢谢!
推荐答案
这是您要寻找的吗?
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);
来源: https://gist.github.com/953059
这篇关于访问Mongoose.js模式中Enum字段的有效值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文