数组?"/>
为什么在mongoose中使用find方法时console.log返回空数组?
我是后端开发人员的新手。我正在尝试检查集合中是否已有用户,如果没有,则控制台日志为“ no”。我在'const b'中没有指示的数据,但是我一直在终端中获取空数组,而不是'no'。
const b = {email: "[email protected]", password: "wwww"}
MyModel.find(b)
.then(exUs =>{
if(exUs){
console.log(exUs)
} else {
console.log("no")
}
})
回答如下:find
总是返回一个cursor
(如果没有文档,则可以为空[]
),因此您的if条件将始终为true,并且如果文档为零,它将打印空数组[]
(永远不会返回游标空值)。
更多推荐
为什么在mongoose中使用find方法时console.log返回空数组?
发布评论