Need advise last lesson of mongodb/mongoose

Hi, i’m studying this lesson, following your hint i’ve written this code for the query chain:

const queryChain = (done) => {
  const foodToSearch = "burrito";

Person.find({favoriteFoods: foodToSearch})
  .sort({ name: -1 })
  .limit(2)
  .select({ age: 0 })
  .exec(function(error, people) {
    
    if(error) return console.log(error);
    
    
    done(error, data)
  });

};

there sure be something wrong, i don’t pass the test, hope you can lead me to the solution!

Also in the mongoose’s documentation can’t find model.sort :thinking:

Hello, buddy. You may use .sort({name: 1}) instead .sort({name -1}). Have fun! :wink:

I’ve written this code:

Person.find({favoriteFoods: foodToSearch})
  .sort({ name: 1 })
  .limit(2)
  .select({ age: 0 })
  .exec(function(error, people) {
    
    if(error) return console.error(error);

  
    
    done(error, data)
  });

};

but still doesn’t work, it gives me error. Hope for your help

As mentioned in the documentation, the .find() method applied on a Model returns a Query. So you should look into Query.sort() :slight_smile:

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.log(err)
    done(null, data)
  });
};

Don’t know this will help or not , can you try the done() with null and data . done(null, data)

Thank you for your advices, i’m working on it :slightly_smiling_face: