MongoDB and Mongoose -- model.find() Done Argument Not Complete

I’m trying to complete the model.find() challenge, but I keep getting the following error in my terminal when running the FCC tests: image .

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

From reading docs and looking at examples, I thought my code should be handling done well enough to return the search. What should I try changing?

If it helps, this is my repl.it.

Hello there,

The done function in the tests is here:

findByName(pers.name, function(err, data) {
      clearTimeout(t);
      if(err) { return next(err) }
      if(!data) {
        console.log('Missing `done()` argument');
        return next({message: 'Missing callback argument'});
      }
      res.json(data);
      Person.remove().exec();
    });

So, you are better off seeing what happens when you console.log(peopleFound) in your findPeopleByName function. Let us know what you find.

Thanks! So I tried to explore with console logs, and I’m not even sure if my basic function is working. I tried console logging “peopleFound” and “personName,” but neither printed even when I attached text to the console log.

Based on this, would I be correct to assume the function isn’t even working? Or would this be a problem with my schema?

After a second look, I found the issue:


var findPeopleByName = function(personName, done) {
    console.log(peopleFound + " Test1")
  Person.find({name: personName}, function (err, peopleFound) {
    console.log(peopleFound + "Test2");
    if (err) return console.log(err);
    done(null, peopleFound);
    console.log(peopleFound + "Test3")
  });
};
// Find all the people having a given name, using `Model.find() -> [Person]`
// In its simplest usage, `Model.find()` accepts a **query** document (a JSON
// object ) as the first argument, and returns an **array** of matches.
// It supports an extremely wide range of search options. Check it in the docs.
// Use the function argument `personName` as search key.

var findPeopleByName = function(personName, done) {
  
  done(null/*, data*/);

};

Further down, the function (variable) is redefined. Delete this, and it should work.

Did you create the first function?