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!
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.
For those who still didn’t get the answer. This is what I came up with:
Step 1: find the object- look for what your did in the previous challenges to find an object.
Step 2: sort the name in ascending order. Use an object and it’s corresponding key which you want to search. Tip: ascending order is represented by a 1. Check this link for more info: https://mongoosejs.com/docs/api.html#query_Query-select
Step 3: limit is just a single parameter for how many you want to limit it to.
Step 4: Select also uses an object to hide certain property from the result. Here 0 means false and hides name property, wherein 1 means true and will show age property.
Step 5: The exec function requires 2 parameters and returns your usual callback.
If you still can’t solve it then below you may find my answer. Cheers everybody!
var queryChain = function(done) {
var foodToSearch = "burrito";
var jsonObject = {favoriteFoods : foodToSearch};
Person.find(jsonObject).sort({name: 1}).limit(2).select({age: 0}).exec((err, data) => {
(err) ? done(err) : done(null, data);
})
};
Lol. Sometimes when I click the “I completed this challenge” button I pass and sometimes I don’t. It turns out I was using the key name “field” from the mongoose docs inside sort() instead of the name key in our project.