gpt4 book ai didi

node.js - 错误 : Virtual path "password" conflicts with a real path in the schema

转载 作者:行者123 更新时间:2023-12-05 02:15:48 26 4
gpt4 key购买 nike

当我尝试在我的模式中添加虚拟时,出现以下错误并且无法解决它...请帮助解决它并让我知道为什么会这样

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);

最佳答案

如果您使用虚拟'password',则无需在架构中声明真实密码。此外,您还没有声明 hashedPasswordsalt

你的架构必须是这样的

var recipientSchema = new mongoose.Schema({
email: { type: String, trim: true, required: true },
hashedPassword: { type: String, required: true },
salt: { type: String, required: true }
});

关于node.js - 错误 : Virtual path "password" conflicts with a real path in the schema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51095756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com