const User = new mongoose.Schema(
{
hashedPassword: { type: String, required: true },
}
)
在保存之前,我创建了一个用于散列值的虚拟字段。
User.virtual('password')
.get(function () { return this.hashedPassword })
.set(function (password) {
bcrypt.hash(password, 10)
.then((hash) => {
this.hashedPassword = hash
})
})
如果我发送查询(正文),我会收到错误
// Query
User.create(req.body)
.then((newUser) => {
....
// Body
{
"email": "email@email.com",
"password": "Test12345"
}
// Response
{
"errors": {
"hashedPassword": {
"message": "Path `hashedPassword` is required.",
"name": "ValidatorError",
...
我的错误在哪里?