额 都不知道改怎么表达了亲,刚刚接触照着慕课网教程吵得,但是为啥我存储的user不是加密后的呢? UserSchema.pre('save', function(next) { var user = this; if(this.isNew) { this.meta.createAt = this.meta.updateAt = Date.now(); } else { this.meta.updateAt = Date.now(); } bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) { if (err) return next(err) bcrypt.hash(user.password, salt, function(err, hash) { if (err) return next(err) user.password = hash; console.log(user); next() }); }); next(); });
左边是数据库读出来的,右边是上面代码中console出来的,为什么存储的password没有被加密呢?