MongoDB and Mongoose Challenge - findPersonById problem

I cannot pass this challenge

The ideia is to find a document by id, this is what I am trying:

var findPersonById = function(personId, done) {
    Person.findById(personId, (err, data) => err ? done(err) : done(null, data));
};

But the console of the challenge returns this:

// running test
Timeout has occurred
// tests completed

What happens if you return the Person model?

var findPersonById = function(personId, done) {
    return Person.findById(personId, (err, data) => err ? done(err) : done(null, data));
};

It looks like that nothing has changed.
I still get timeout on the console =(

Could you post a link to your Glitch project?

My Glitch link is https://cuddly-pendulum.glitch.me/.
But I found the problem today. I made a variable for the callback function, like this:

var callbackFunction = "(err, data) => err ? done(err) : done(null, data)";

And then, used this variable:

var findPersonById = function(personId, done) { 
    Person.findById(personId, callbackFunction); 
};

Today, I removed the variable and put all the code inside findPersonById:

var findPersonById = function(personId, done) { 
    Person.findById( personId, (err, data) => err ? done(err) : done(null, data) ); 
};

And it works.
Thanks for trying to help @PortableStick!
I would appreciate any comment about my project, because this callback function is so confusing, and MongoDB and Mongoose challenges of freeCodeCamp are also confusing and not self-explanatory for a first timer like me.

Yeah, that would do it. Keep this in mind: callback functions are never strings.

I know it’s confusing, but just keep at it. No amount of reading will ever be a better teacher than first hand experience, so just keep working at the challenges, and even repeat them a few times. You will get it in no time.

1 Like