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

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


Not able to pass this challenge.

Can anyone see what’s wrong?

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


I got it. When sorting alphabetically, it has to be sorted in “asc” order not “desc” order.


hi, thanks for your post! But a little question about this chanllenge, I don’t know the specific usage about sort() , limit() and select() , they didn’t describe in the chanllenge and I searched for them in the Mogoose doc or JS or SQL, still not knowed exactly meanings about them , could you tell me how to know that? thank you!


This doc is pretty good at explaining those.

sort is self explanatory, you can just pass in different parameters to sort how you want. Limit only grabs whatever parameter you pass in and return only that number of results. select only returns specific entries in this case age. It could be name or gender if you pass in those parameters.

Hope this helps!


It’s great for me , I just realized these points involved in MongoDB’s syntax, I will review that. Thanks again!


Hello everyone,

Do not know the answers to these questions…

  1. Will there be journal replay programs in case of incomplete entries (if there is a failure in the middle of one)?

  2. When using replication, can some members use journaling and others not?

Can anyone help me, please? Or should I go towards MongoDB Tutorial?


i don't understand why .select("-age")

i am using .select({age : 0})


You should read some doc


@akidox thank you for pointed that out, freecodecamp community really amazing.