Create a Multi-tenancy Application In Nest.js – Part 3

Recap

In the first part, create a Multi-tenancy Application In Nest.js - Part 1, we set up the Nest.js framework and configured and tested the microservices architecture application using Nest.js. In its second part, we used Sequelize and Mongoose to access the database and tested for both MySQL database and MongoDB.

Async Connection

In this part; we will see how to let the application connect to multiple databases depending on the request. Since it is a multi-tenancy application, each tenant has their own database containing their data accessing the same application, thus the application needs to connect to different databases. We will change the pass repository option method and use forRootAsync() instead of forRoot(), we need to use a custom class for configuration.