Freecodecamp MongoDB Mongoose chain query not proceeding

Tell us what’s happening:
Why This is not working, I test it using console.log but it works

var mongoose=require('mongoose');
 mongoose.connect(process.env.MONGO_URI);


var Schema=mongoose.Schema;
var PersonSchema=new Schema({
  name: {type: String, required:true},
  age: Number,
  favoriteFoods: [{type: String,unique: true}]  
});
var Person=mongoose.model('Person',PersonSchema); //model



var queryChain = function(done) {
  var foodToSearch = "burrito";
  
  Person.find({favoriteFoods: foodToSearch}).sort({name: 'asc'}).limit(2).select("-age").exec(function(error, people) {
    console.log(people)
    done(error, people);
    if(error){
       done(error);
    }
  })
};

queryChain(function(a,b){
  console.log("------")
  console.log(b)
})



exports.PersonModel = Person;
exports.queryChain = queryChain;

Your project link(s)

solution: https://replit.com/@giftsongabogen/boilerplate-mongomongoose-1

Your browser information:

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

Challenge: Chain Search Query Helpers to Narrow Search Results

Link to the challenge:

Welcome there,

You appear to have deleted a large portion of the boilerplate code: boilerplate-mongomongoose/myApp.js at gomix · freeCodeCamp/boilerplate-mongomongoose · GitHub

Without the boilerplate code, and without following the instructions, it is unlikely the tests will pass.

Hope this helps.

I passed it, and no deleteing the boilerplates was not the problem because the other codes in the boilerplate has nothing to do with the queryChain functionality. I just forgot to add a second parameter on queryChain function which is the foodToSearch parameter​:grin::grin:. Still thanks for the response. Appreciate it.

I passed it, and no deleteing the boilerplates was not the problem because the other codes in the boilerplate has nothing to do with the queryChain functionality. I just forgot to add a second parameter on queryChain function which is the foodToSearch parameter​:grin::grin:. Still thanks for the response. Appreciate it.

That should be like this

function queryChain(done, foodToSearch) {

}

And the declaration of foodToSearch inside the function should be deleted.

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