Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a REST API With Express Modeling Data for the API Default Values in Mongoose

Couldn't these call backs be done in promises?

I am getting an error saying these callbacks should be done with the promise library?

2 Answers

Cezary Burzykowski
Cezary Burzykowski
18,291 Points

Yes, because they should.

You can still use callback functions and the code will work, but most of the Mongoose methods return promises (remove(), save(), find(), findOne(), etc.) and the best way to deal with promises is with .then().

For example:

animal.save().then( here goes function that does something with the result)

Cezary Burzykowski great! Thanks for the tip.