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

Tell us what’s happening:
Describe your issue in detail here.

Hello, I am having issues passing the last task on MongoDB and Mongoose.

My current Issue is that as I followed the instructions, I used the Person reference to search the documents within their using find. I passed the object to the find method, which I subsequently chained with sort, limit and select. After using these methods to apply the necessary filters, I then chained exec to pass my callback to and handle any errors within the execution if there were any.

Below is what I have thus far, and have rewritten it more than a couple of times.

Would love some insight on what I am doing wrong.
const foundPerson = Person.find({ favoriteFoods: foodToSearch })

foundPerson
.sort({ name: 1 })
.limit(2)
.select({ age: 0 })
.exec((err, data) => {
if (!err) {
done(null, data);
console.log(Chained Successfully. Results: ${data})
} else {
console.log(err);
};
});

Your project link(s)

solution: boilerplate-mongomongoose - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15

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

Link to the challenge:

hello and welcome to fcc forum :slight_smile:

what error/s your are getting?!

Thanks for responding. At the time I was getting no error. I had to stop the process then restart it.

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