1
List.findOne({name:tagname},function(err,fidlist){
    if(!err){
        if(!fidlist){
            console.log("doesnt exist");
        }
        else {
            console.log("exist");
        }
    }
});

How to fix the code showing Model.findOne() no longer accepts a callback can some one help me out.

Andy Preston
  • 779
  • 4
  • 9
  • 23

1 Answers1

0

The accepted answer can help you understand better: Mongoose - What does the exec function do?

To get the same functionality of your code with exec(), you can do this:

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");
    }
  });
Nasem
  • 417
  • 2
  • 7
  • 15