Why do I need to provide a name when creating a new model?

I am just starting to learn MongoDB and Mongoose, I cannot get the point of the first argument to the function model

. Why do I need to specify a string as a name and what is the purpose?

// Schema
var CustomerSchema =  mongoose.Schema({
    name: String
});

// Model, that is the constructor
var Customer = mongoose.model('Customer', CustomerSchema);

// Instance, a particular customer
var john = new Customer({});

      

+3


source to share


1 answer


The lower, plural version of the model name is used for the name of the MongoDB collection associated with (for example, customers

in this case).



It also allows your code to search the model by name via mongoose.model('Customer')

.

+2


source







All Articles