我的模型看起来像这样,但当我尝试使用app.controller('myController', function($scope) {
$scope.myMethod = function() {}; //Not callable from controller passed to directive
this.myMethod = function() {}; //IS callable from controller passed to directive
});
时,它会显示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)
}
答案 0 :(得分:7)
Mongo"发现"返回结果的可迭代游标(可能没有)。如果您希望仅获得一个结果,请尝试" findOne"代替。这将返回一个文档。