Mongoose always returning an empty array NodeJS

后端 未结 5 1093

I have tried using find and findOne and both are not returning a document. find is returning an empty array while findOne

5条回答
  •  不要未来只要你来
    2020-11-22 10:52

    Had kinda same problem. The solutions above didnt work for me. My app never returns error even if the query is not found. It returns empty array. So i put this in my code:

    if(queryResult.length==0) return res.status(404).send("not found");
    

提交回复
热议问题