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 Getting More from Mongoose

please help with static methods

im so confused! at 9:08 he says "lets create a static method on the animal model." then he proceeds to define it on the schema with

schemaName.static.nameOfMethod

if we create it on the animal model wouldnt it be

modelName.static.NameofMethod

please help!

1 Answer

Antti Lylander
Antti Lylander
9,686 Points

Yeah, a schema is used to create a model. So you define methods and statics on the schema. Methods are called on model instances and statics live on the model itself. See:

https://mongoosejs.com/docs/2.7.x/docs/methods-statics.html