Use model.findById() to Search Your Database By _id

For the mongodb/mongoose project: Use modle.findById() to Search Your Database By _id, I am runing into an error. Every time that I try to test my code, I get the Error: missing callback argument.
When I check the Glitch logs, it tells me: Missing done() argument

Here is my code for that section.


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

For the previous two challenges, I have used almost identical code and never ran into any problems. I am starting to wonder if it is a bug in the testing code.

**Here is a link to my project, if you want to look at the previous challenges’ code: https://glitch.com/edit/#!/shadow-sushi

You need to remove the Person form your Person.personId.

1 Like

Hi sir,
Could you please explain why we need to remove the Person from Person.personId? I add Person to previous challenges and it all passed.

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

1 Like

Other possibility:

var findPersonById = function(personId, done) {   
  Person.findById(personId, function(err, data){
     if(err) { done(err); }
     else { done(null,data); }
})  
};

Hi,

I have the answer to this test, but why can’t you use an arrow function like in the other exercises.

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

};

It says that the arrow function is the ‘unexpected token’.

When using arrow function, don’t use the word “function”

..., (err, data) => (err) ? done(err) : done(null, data)

Cheers, thanks for this!

Still Test Timed out. If someone want to help me,can visit to this URL. https://glitch.com/edit/#!/join/cda43697-88bb-4a2d-81f0-08bf740ea0b4