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

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

#1

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) => {
     if(err)
       done(err);
    done(null, data);
  })
};

https://learn.freecodecamp.org/apis-and-microservices/mongodb-and-mongoose/chain-search-query-helpers-to-narrow-search-results


#2

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


#3

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!


#4

This doc is pretty good at explaining those. http://mongoosejs.com/docs/queries.html

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!


#5

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