From the course: Databases for Node.js Developers
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Integrating the model into our application - Node.js Tutorial
From the course: Databases for Node.js Developers
Integrating the model into our application
- [Narrator] As I said, we need to make this model we just created now accessible in our Fastify application. To do that, we will update our Mongoose plugin. So I open that. It's in source, plugins, databases, mongoose. The goal is to attach the item model to the Fastify instance so that it's available throughout our app. The best way to do this in Fastify is by using decorators. Decorators allow us to add properties or methods to the Fastify instance, making them accessible everywhere in the application on the Fastify object that is as you also see on line four, always passed around through all our plugins that we're using, and routes are also basically plugins. In other frameworks, you might simply import the model wherever it's needed. This works in Fastify, too, but it's not a deal for a modular setup. Using decorators ensures a consistent way to use your models throughout your application. So what I'm doing now right on top is I will import the item model. So I add import. In…
Contents
-
-
-
-
-
(Locked)
Managing product data with MongoDB33s
-
Setting up MongoDB with Docker2m 30s
-
(Locked)
Exploring MongoDB with Compass1m 19s
-
(Locked)
Introducing Mongoose2m 59s
-
(Locked)
Setting up Mongoose and connecting it to MongoDB10m 14s
-
(Locked)
Building a model for our products5m 25s
-
(Locked)
Integrating the model into our application3m 55s
-
(Locked)
Populating MongoDB with sample data2m 6s
-
(Locked)
Querying items with Mongoose9m 19s
-
(Locked)
Filtering items by tag4m 27s
-
(Locked)
Item administration: Listing and loading6m 32s
-
(Locked)
Item administration: Create, update, and delete15m 14s
-
(Locked)
Optimizing queries with indexes5m 33s
-
(Locked)
Performing text search in MongoDB5m 34s
-
(Locked)
-
-
-
-