当我尝试在架构中添加Virtuals时,出现以下错误,无法解决...请帮助解决该问题,并让我知道这是为什么
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var recipientSchema = new mongoose.Schema({
email: { type: String, trim: true, required: true },
password: { type: String, required: true },
});
/**
* Virtuals
*/
recipientSchema
.virtual('password')
.set(function(password) {
this._password = password;
this.salt = this.makeSalt();
this.hashedPassword = this.encryptPassword(password);
})
.get(function() {
return this._password;
});
module.exports = mongoose.model('Recipients', recipientSchema);
答案 0 :(得分:1)
如果您使用虚拟的“密码” ,则无需在架构中声明真实的密码。另外,您还没有声明 hashedPassword 和盐
您的架构必须是这样
var recipientSchema = new mongoose.Schema({
email: { type: String, trim: true, required: true },
hashedPassword: { type: String, required: true },
salt: { type: String, required: true }
});
答案 1 :(得分:0)