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 :)
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With