Tell us what’s happening:
This part of the code is giving error.
Question: Modify the queryChain
function to find people who like the food specified by the variable named foodToSearch
. Sort them by name
, limit the results to two documents, and hide their age. Chain .find()
, .sort()
, .limit()
, .select()
, and then .exec()
. Pass the done(err, data)
callback to exec()
.
From: MongoDB and Mongoose - Chain Search Query Helpers to Narrow Search Results
My code so far
Person.find({ favouriteFoods:foodToSearch })
.sort({ name: ‘asc’ })
.limit(2)
.select({ name:1,age: 0,favouriteFoods:1 })
.exec(function(err, data) {
//do something here
if (err) return console.error(err);
done(null,data);
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
.
Challenge: Chain Search Query Helpers to Narrow Search Results
Link to the challenge: