【发布时间】:2018-06-23 02:21:22
【问题描述】:
我希望属性“localized_words”是一个对象映射字符串到array。
使用下面的代码,我只能确保它是一个Object,但是如何确保值是严格数组?
var schema = mongoose.Schema({
// example
// this should fail : { en: [], fr: 123 }
// this should succeed: { en: [], fr: [] }
// but with current code, any object will pass validation
localized_words : { type: Object }
});
我要存储的数据示例:{en: ['car', 'apple'], fr: ['voiture', 'pomme']}
【问题讨论】:
-
能否包含您要存储的示例数据?
-
@Khang 刚刚做了
标签: node.js mongodb object mongoose