2

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

Sanyam
  • 64
  • 3
  • 11

2 Answers2

2

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

cmbuckley
  • 40,217
  • 9
  • 77
  • 91
1

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.

RobC
  • 22,977
  • 20
  • 73
  • 80
Nikhil Vats
  • 291
  • 3
  • 7