Test not passing when chaining helpers

Tell us what’s happening:

Repl:https://repl.it/@akshitchaturved/boilerplate-mongomongoose
I’m following all the hints yet I’m unable to pass the test. Pls help me out.

Your code so far

var queryChain = function(done) {
  
  
 Person.find({ age: 55 })
  .sort({ name: -1 })
  .limit(5)
  .select({ favoriteFoods: 0 })
  .exec(function(error, people) {
    if(error){
       done(error);
    }
    
    done(null, people);
  })

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.3 Safari/605.1.15.

Challenge: Chain Search Query Helpers to Narrow Search Results

Link to the challenge:

  1. You are not using foodToSearch for the .find()

  2. The default sort order is ascending, which I believe is what is expected.

  3. You are not limiting the results to two documents.

  4. You are not excluding the age.

I would suggest you look at the docs, for find and query.

Thanks for the quick feedback. I’ve made the suggested changes but I am unable to pass the test.

var queryChain = function(done) {
  foodToSearch = "Chickpea"
  Person.find({favoriteFoods: foodToSearch}).sort({name:1}).limit(2).select({age:0}).exec(function(error, people) {
    if(error){
       done(error);
    }
    
    done(null, people);
  })
  
};

Why did you change the value of foodToSearch and why did you remove the declaration?

Edit: you should also keep the code format like it was, it’s really hard to read now.

No value for foodToSearch was provided beforehand.I’ve been taught to use ‘var’ instead of ‘const’ (makes it more flexible). So, I changed the format.

Yes, it was. Here is the starter code.

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

  done(null /*, data*/);
};

Not sure who taught you that but I would unlearn that ASAP.

I’ll use const from now on.

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

I still can’t pass the test. :frowning_face:

Your code seems to be passing for me. Did you remember to restart the server?

I restarted the server , still no luck.

Not sure what is wrong.

When I take your code and put it in my own project it passes the test, if I fork your project and add my own .env file it passes the test.

Are you sure you are connecting to the DB correctly?