MongoDB and Mongoose - Use model.findOne() to Return a Single Matching Document from Your Database -Timeout has occured

Hello free code camp..,i need help MongoDB and Mongoose - Use model.findOne() to Return a Single Matching Document from Your Database , i cannot pass this, it said "Timeout has occured ", here are my code

var findOneByFood = function(food, done) {
Person.findOne({favoriteFoods: ‘food’}, function(err, data){
if(err){
return done(err);
return done(null, data);
}
});

};

here my link project.

1 Like

You just need to move out the second return statement from the curly braces, like this:

var findOneByFood = function(food, done) {
  Person.findOne({favoriteFoods: ‘food’}, function(err, data){
    if(err){
      return done(err);
    }
    return done(null, data);
  });

};

hi...@ace1122sp, well thank you to point that out, silly me, but still does't work it said missing callback argument

still keep looking... ,whats the problem? any suggestion?

1 Like

i open to the console in glitch, it said ''could not find node 4.4.5, using Node 8" help

Perhaps use the variable food without quotation marks in your query?

about this ''could not find node 4.4.5, using Node 8", do you have “start” script in your package.json? I had similar problem, because I forgot to write “start” command…

hi... @ace1122sp , @ppiron, thank you so much guys you tried to help me, i found the answer, got it where i made mistakes.

var findOneByFood = function(food, done) {

Person.findOne( { ‘favoriteFoods’: food }, (err, data)=> err ? done(err) : done(null, data) );

};

omg… I didn’t notice that food was an argument and not a string… :blush:
And as always, the smallest bugs are hardest to notice. :relieved: I’m glad you’ve resolved this… :smiley: