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 trialSaud Tauqeer
Courses Plus Student 8,099 Pointsmongoose.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
Treehouse TeacherI 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.
Lee Vaughn
Treehouse TeacherHi Saud,
The first argument is the name of the collection that the model is for, which in this case is User.
Saud Tauqeer
Courses Plus Student 8,099 Pointsso the const User and the argument User are unrelated? such as
const User = mongoose.model('userAny' , UserSchema);
and it will create a userAnys collection?
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 PointsAll good. So for the sake of simplicity we put in same names.