Chain Search Query Helpers to Narrow Search Results - Tests are not passing! Why? Any problem in my code?

I get the following error:

// running tests
Chaining query helpers should succeed
// tests completed

Here is the function that I have written.

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

I see no problem in the code and the example solution is easy to understand but still the tests passing is so frustrating and it wastes a lot of time.

Any idea what is wrong?

Your project link(s)

solution: https://replit.com/@innovations/boilerplate-mongomongoose

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36

Challenge: Chain Search Query Helpers to Narrow Search Results

Link to the challenge:

The following code worked:

const queryChain = function(done) {
  const foodToSearch = "burrito";
  Person.find({favoriteFoods: foodToSearch}).sort({name: 1}).limit(2).select({age: 0}).exec((err, data) => {
    (err) ? done(err) : done(null, data); 
  })
};

This also worked:

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

This also worked:
const queryChain = (done) => {
const foodToSearch = “burrito”;
Person.find({favoriteFoods: foodToSearch}).sort({name: 1, age: 0, favoriteFoods: 1}).limit(2).select({age: 0}).exec(function(err, data){
if(err) return console.error(err);
done(null, data);
})
};

So what is wrong with the code in the question section? Why would it not pass the tests?

You must fix the nmae to name in .sort function,
only age want to hidden so .select must contain only age: 0,
it is not indicated but sorting must be -Ascending- ( 1 ) by name.

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