O'Reilly logo

Hands-On Full Stack Web Development with Aurelia by Erikson Haziz Murrugarra Sifuentes, Diego Jose Arguelles Rojas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating models

Now that we have our schema, it is time to tell Mongoose that we want to use that Schema to create new objects in order to send them to MongoDB. To do this, we need to create a model by passing the schema already defined. Open the mongoose-connection.js file and add the following code:

...const Team = mongoose.model('team', TeamSchema)

Believe it or not, we just need this line to interface our schema to MongoDB. In this line, we tell Mongoose that we want to call our collection as team. The result of calling mongoose.model will be an object that is the model; we will use this object to create new instances. The Team object also contains built-in CRUD methods, so we will use them to create CRUD operations to the database.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required