Reputation: 104
Why the name of the Model is Capitalized. As in their documentation, they have capitalized it.
var schema = new mongoose.Schema({ name: 'string', size: 'string' });
var Tank = mongoose.model('Tank', schema);
Why is Tank
capitalized here? Is there any specific reason?
Sorry if this is not a good question. Any help would be appreciated :)
Upvotes: 3
Views: 3304
Reputation: 301
Reference Mongoose Documentation
var schema = new mongoose.Schema({ name: 'string', size: 'string' }); var Tank = mongoose.model('Tank', schema);
The first argument is the singular name of the collection your model is for. ** Mongoose automatically looks for the plural, lowercased version of your model name. ** Thus, for the example above, the model Tank is for the tanks collection in the database.
Upvotes: 1
Reputation: 42507
This is merely a coding convention. The Tank
model is being viewed as an instantiable class:
var small = new Tank({ size: 'small' });
According to typical coding conventions, class names should be UpperCamelCase
with the first letter capitalised, and instance variables should be in lowerCamelCase
(as should methods).
Upvotes: 2