[MongoDB] Model.find() - Constantly getting missing callback error

[MongoDB] Model.find() - Constantly getting missing callback error
0

#1
var findPeopleByName = function(personName, done) {
    Person.find({ name: personName }, function (err, data) {
    if (err) return done(err);
    return done(null, data);
    })
};

Every time I run this code I get “missing callback” errors, and in the status bar for the Glitch project it says “missing done() argument” even though I am calling done in the function. I have searched the forums and perused through the mongoose docs but have not yet found a solution to this problem. Has anybody encountered and solved this problem before?


#2

Hi. Your code works for me and passes the challenge test when I run it. It is also virtually identical to the code I wrote when I did the challenge last week:

var findPeopleByName = function(personName, done) {
  Person.find({
    name: personName  
  }, (err, matches) => {
    if(err) return console.error(err);
    done(null, matches);
  });
};

The only difference being I didn’t use ‘return’ before my done() functions. Makes me think it’s a problem in another part of your code. Maybe you’re missing a done() in one of the earlier challenges in the file?


#3

Well, running your code passes the code test, even though like you said it’s almost identical to my own. i even tried returning the done() function like you did, and it failed… but thank you anyway!