Mongoose Tutorial - Node
What is Mongoose?
Mongoose - Terminologies
Mongoose In Action - Referencing
Mongoose In Action - Defining the Schema
Mongoose In Action - Exporting a Model
Mongoose - Creating an Application
Mongoose - CRUD Operations
Author Profile Altaf Shaikh
Altaf Shaikh

BE Engg | Python Dev | Content Writer | Founder of TeachMeBro | Blockchain Dev | Django

Mongoose In Action - Exporting a Model

January 25th 2021

Mongoose In Action - Exporting a Model
Mongoose In Action - Exporting a Model

We need to call the model constructor on the Mongoose instance and pass it the name of the collection and a reference to the schema definition.

var Todos = mongoose.model("Todo", todoSchema);

And now finally lets export this model, so that we can use this model throughout the project.

module.exports = Todos;

Now, we understand how we can define a schema and using schema how we can make our model. So this was the major part with the Mongoose model creation and now we have to make use of this model.

In this next section, we will see how to setup the project and start writing some code.