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

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

#1

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.


#2

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);
  });

};

#3

[email protected], 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?


#4

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


#5

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


#6

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…


#7

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) );

};


#8

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: