[英]TypeError: Cannot read property 'then' of undefined with find() monk
I am working with monk, and when I look for a user in the database using a function, I want their to return a boolean depending on if its found or not.我正在与和尚一起工作,当我使用函数在数据库中查找用户时,我希望他们根据是否找到来返回一个布尔值。 Here is the code:这是代码:
Function:功能:
function userExist() {
users
.find()
.then(result => {
console.log(result)
if(result.length != 0) {
return true;
} else {
return false;
}
})
} }
calling the function(here is the error):调用函数(这是错误):
userExist().then(received => {
console.log(received);
})
You should return your promise inside your userExist function.您应该在 userExist 函数中返回您的承诺。 Otherwise, you have just a function and not a promise to call then().否则,您只有一个函数,而不是调用 then() 的承诺。
function userExist() {
return users
.find()
.then(result => {
console.log(result)
if(result.length != 0) {
return true;
} else {
return false;
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.