在模式默认情况下使用自定义函数?
Use custom function in default of schema?
我有这样的架构:
new mongoose.Schema({
name: String,
uniq: {type: String, default: Math.random() + "a"},
})
我无法获得随机数,但只有 null
用于 uniq 字段
是否可以默认使用自定义函数?
使用
uniq: {type: String, default: function(){ return Math.random() + "a"; } }
我有这样的架构:
new mongoose.Schema({
name: String,
uniq: {type: String, default: Math.random() + "a"},
})
我无法获得随机数,但只有 null
用于 uniq 字段
是否可以默认使用自定义函数?
使用
uniq: {type: String, default: function(){ return Math.random() + "a"; } }