From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Connecting to MongoDB database

Connecting to MongoDB database

In this lecture, we will see how to connect NestJS application with the MongoDB database. So let's begin by installing the necessary packages. I'll give the command npm install hyphen hyphen save mongoose, which is the node mongoose driver. Nest uses the core mongoose driver to connect and run queries with the MongoDB database. Along with this, I'll also give the nestjs slash mongoose package. Here the nestjs acts as a wrapper around the traditional mongoose driver package. Though this package is not really required for using the mongoose, we can still make it work using only the mongoose driver. But using wrapper makes things more smoother with nestjs application as it easily integrates with the nest environment, allowing us a total TypeScript support, and we can also inject the modules or services in the file. I would also like to mention that nest does not use type ORM for MongoDB. That is no SQL databases. That's the reason why we are using the core Mongoose driver. Type ORM is…

Contents