I seem to be stucked on the last question of this exercise and I can’t seem to understand where I am wrong.
I tried this :
`const queryChain = (foodToSearch, done) => {
Person.find({favoriteFoods:foodToSearch})
.sort("name")
.limit(2)
.select('-age')
.exec(function(err,data){
if(err)
{
console.log(err);
}
done(err,data);
})
}`
I seem to get the type error: done is not a function. How can I solve this?
You changed the function parameters, done
has to be the first parameter. Also, the variable foodToSearch
was already declared inside the function, it isn’t a parameter.
Starting code:
const queryChain = (done) => {
const foodToSearch = "burrito";
done(null /*, data*/);
};
Just as an aside, it is important to understand that you can’t change the order of function parameters without changing the arguments. As you are not the one calling the function, changing the parameters is pretty much guarantied to cause trouble.
The error is also telling you this. The reason why done
is not a function is that it is passed as the first argument, but your first parameter is now foodToSearch
so that is what contains the callback that should have been passed to done
.