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 User Authentication With Express and Mongo User Registration Defining a Mongo Schema with Mongoose

mongoose.model

const User = mongoose.model('User' , UserSchema);
module.exports = User;

what's the first argument "User" into the mongoose.model for? is this the same User as the User in the mongoose.model?

2 Answers

Lee Vaughn
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Lee Vaughn
Treehouse Teacher

I guess it depends on how you define unrelated. They are separate things that all have the same name and the reason they are all named the same way is because they all kind of tie together, just like the variable name that you use to require the user file in index.js. You don't necessarily have to use the same name for your collection, the model, and the variable in index.js but it is much simpler to follow if you do.

All good. So for the sake of simplicity we put in same names.

Lee Vaughn
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Lee Vaughn
Treehouse Teacher

Hi Saud,

The first argument is the name of the collection that the model is for, which in this case is User.

so the const User and the argument User are unrelated? such as

const User = mongoose.model('userAny' , UserSchema);

and it will create a userAnys collection?