javascript Model.findOne()不再接受回调有人能帮我吗

jv4diomz  于 2023-03-28  发布在  Java
关注(0)|答案(1)|浏览(99)
List.findOne({name:tagname},function(err,fidlist){
    if(!err){
        if(!fidlist){
            console.log("doesnt exist");
        }
        else {
            console.log("exist");
        }
    }
});

如何修复显示Model.findOne()不再接受回调的代码,有人能帮我吗?

ao218c7q

ao218c7q1#

可接受的答案可以帮助您更好地理解:Mongoose - What does the exec function do?
要获得与exec()相同的代码功能,可以这样做:

List.findOne({ name: tagname })
  .exec()
  .then((err, fidlist) => {
    if (err) {
      console.log("something went wrong");
    }
    if (fidlist) {
      console.log("exists");
    } else {
      console.log("doesn't exists");
    }
  });

相关问题