本文介绍了错误:虚拟路径“密码";与架构中的实际路径冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在架构中添加Virtuals时,出现以下错误,无法解决...请帮助解决该问题,并让我知道这是为什么

When I am trying to add Virtuals in my schema I am getting following error and could not able to solve it... Please help to resolve it and please let me know why this is happeing

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

推荐答案

如果您使用虚拟密码" ,则无需在架构中声明真实的密码.另外,您还没有声明 hashedPassword

If you use virtual 'password' you don't need to declare the real one in schema. Also you haven't declared hashedPassword and salt

您的架构必须是这样

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

这篇关于错误:虚拟路径“密码";与架构中的实际路径冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 19:40