Search code examples
javascriptmongodbmongoose-models

Capitalization of the model name (Mongoose)?


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 :)


Solution

  • 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).