我的模型看起来像这样,但是当我尝试使用时verifyPassword
,它说TypeError: user.verifyPassword is not a function
const User = new mongoose.Schema({ name: { type: String, required: true }, password: { type: String, required: true }, avatar: String, token: String, role: String, permissions: Array, email: { type: String, unique: true, required: true }, joined: { type: Number, default: ( new Date() * 1 ) } }) User.methods.verifyPassword = function (password) { return bcrypt.compare(password, this.password) }
我这样用它.
yield User.find({ email: this.request.body.email }).exec() .then( user => { if ( user.verifyPassword(self.request.body.password) ) { self.status = 200 self.body = { token: user.token } } else { self.status = 500 self.body = "Problem signing in." } }, error => { self.status = 500 self.body = "Problem signing in." })
小智.. 7
Mongo的"find"返回一个可迭代的结果游标(可能没有).如果您希望仅获得一个结果,请尝试使用"findOne".这将返回一个文档.
Mongo的"find"返回一个可迭代的结果游标(可能没有).如果您希望仅获得一个结果,请尝试使用"findOne".这将返回一个文档.