Can't pass MongoDB - Chain Search Query Helpers to Narrow Search Results

Can someone help me out here? The tests keep failing (Time-Out error message) and I don’t know why. Been struggling with this one for a while and checked many similar forum posts, most of which seemed to be unresolved.

Task:

Modify the queryChain function to find people who like the food specified by the variable named foodToSearch. Sort them by name, limit the results to two documents, and hide their age. Chain .find(), .sort(), .limit(), .select(), and then .exec(). Pass the done(err, data) callback to exec().

Relevant snippet:

const queryChain = (done) => {
  const foodToSearch = "burrito";
  Person.find({favoriteFoods: [foodToSearch]})
        .sort({name: 1})
        .limit(2)
        .select({name:1, age: 0, favoriteFoods:1})
        .exec( function(err, people){
          if(err){return console.log(err)};
          done(null, people);
          })
};

Error message:

Chaining query helpers should succeed (Test timed out)

Project link:
solution: https://3000-freecodecam-boilerplate-vsq3tkrrov8.ws-us108.gitpod.io

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36

Challenge Information:

MongoDB and Mongoose - Chain Search Query Helpers to Narrow Search Results

Hello there,

You are not following this section of the instructions exactly:

Pass the done(err, data) callback to exec() .

Hope this helps

Thank you Sky, but I do not see what the problem is. I’m passing the callback exactly the same as I’ve passed it to all the previous Model. methods, which worked. Some examples:

Person.create(arrayOfPeople, function(err,data){
    if(err){return console.log(err)};
    done(null, data);
  } )

Person.find({name: personName}, function(err, data){
    if(err){return console.log(err)};
    done(null, data);
  })

Person.findOne({favoriteFoods: [food]}, function(err,data){
    if(err){return console.log(err)};
  done(null, data)
})

Person.findById(personId, function(err, data){
    if(err){return console.log(err)};
    done(null, data);
})

Hint #6 also uses the same format as I did:

YourQuery.exec(function(err, docs) {
  //do something here
});

I don’t see any anything in the instructions, the hints, nor the manual, that suggest I should do anything different from what I’ve been doing this entire unit.

foodToSearch should not be in an array.

select should only exclude age and not include anything.


It doesn’t really make sense to return a console.log seeing as it returns undefined. You can log the error before calling done(err). The test should pass anyway but it isn’t the syntax taught.

1 Like

That did it, thank you very much.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.