[Error] MongoDB and Mongoose - Chain Search Query Helpers

Hi,
Firstly thanks for the amazing content and the effort put into FCC.

I wanted to mention that I’ve had trouble solving the last exercise of the MongoDB and Mongoose course inside the Bakckend Curriculum.

I could solve all the previous exercises easily, and got stuck in Chain Search Qery Hepers. This was my code:


const queryChain = (done) => {
        const foodToSearch = "burrito";
	Person.find({favoriteFoods: foodToSearch})
		.sort({name: 'asc'})
		.limit(2)
		.select({age: 0})
		.exec((err, data)=>{
			if (err) return done(err);
			done(null, data);
		})
};

The error I got in my logs:

2022-08-11T10:40:39.835943+00:00 app[web.1]: OPTIONS

2022-08-11T10:40:39.836448+00:00 heroku[router]: at=info method=OPTIONS path="/_api/query-tools" host=murmuring-lowlands-28346.herokuapp.com request_id=d8900160-cab3-42d5-8e2f-a670c32283d3 fwd="200.49.119.75" dyno=web.1 connect=0ms service=1ms status=200 bytes=402 protocol=https

2022-08-11T10:40:39.997142+00:00 app[web.1]: POST

2022-08-11T10:40:40.255785+00:00 app[web.1]: Missing `done()` argument

2022-08-11T10:40:40.261787+00:00 heroku[router]: at=info method=POST path="/_api/query-tools" host=murmuring-lowlands-28346.herokuapp.com request_id=bf50b13a-8c36-43d5-b870-ac8ec3c64aee fwd="200.49.119.75" dyno=web.1 connect=0ms service=266ms status=500 bytes=432 protocol=https

The done() argument was there. But for some reason it failed.

====

I tried changing many things in order to make it work, searched all over the forum…

And it finally passed the test, with just a minor change:

const queryChain = (done) => {
	console.log('######\n Starting queryChain');
	const foodToSearch = "burrito";
	Person.find({favoriteFoods: foodToSearch})
		.sort({name: 'asc'})
		.limit(2)
		.select({age: 0})
		.exec((err, data)=>{
			console.log('######\nExecuting');
			if (err) return done(err);
			done(null, data);
		})
};

I’m happy to just continue but I wanted to give a heads up. For some reason the tests were failing. And now they work. All I did was add two console.log statements.

I’m sorry I can’t provide more details. Unfortunately this error was hard to diagnose for me. Now the solution works even without the console.log statements.

Perhaps you can make more of this information than I can. I’m happy to answer any questions or try to pin down the problem.

Again, thank you for what you create in FCC.

Diego