![](/img/trans.png)
[英]Uncaught TypeError: Cannot read property 'find' of undefined
[英]TypeError: Cannot read property 'then' of undefined with find() monk
我正在与和尚一起工作,当我使用函数在数据库中查找用户时,我希望他们根据是否找到来返回一个布尔值。 这是代码:
功能:
function userExist() {
users
.find()
.then(result => {
console.log(result)
if(result.length != 0) {
return true;
} else {
return false;
}
})
}
调用函数(这是错误):
userExist().then(received => {
console.log(received);
})
您应该在 userExist 函数中返回您的承诺。 否则,您只有一个函数,而不是调用 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.