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

Tell us what’s happening:
Describe your issue in detail here.

Chaining query helpers should succeed (Test timed out)
Getting this error
code template :


var queryChain = function(done) {
  var foodToSearch = "burrito";
  Person
    .find({ favouriteFoods: foodToSearch })
    .sort({name: 1})
    .limit(2)
    .select("-age")
    .exec(function(err, data) {
      console.log(data);
      if (err) {
        done(err);
      }
      done(null, data);
    });
};

Your project link(s)

solution: boilerplate-mongomongoose - Replit

Your browser information:

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

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

Link to the challenge:

Looking at your repl, this is the current code you have (different from above):

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

This code passes for me if I rewrite the exec function without arrow syntax:

 .exec(function (err, deletedPersons) { 
   return (err) ? done(err) : done(null, deletedPersons)
   });

I don’t know why this is but perhaps someone can enlighten us?

1 Like

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