needle-innovision / nestjs-tenancy

Multi-tenancy approach for nestjs - currently supported only for mongodb with mongoose
MIT License
186 stars 58 forks source link

How to switch DB instead of creating a new connection #12

Closed sathish76 closed 2 years ago

sathish76 commented 2 years ago

@sandeepsuvit Thank you for the awesome package.

Can you guide me to achieve the following?

Problem:

  1. I have a single MongoDB Atlas Cluster where all my tenant's databases rely on.
  2. Without creating a new connection for every request can I reuse the connection just by switching database using useDb()
sandeepsuvit commented 2 years ago

Hi @sathish76 Thank you for your kind words.

As per the current code the connections once created per request gets cashed in a map and reused next time. Else a new connection is created.

        const exists = connMap.has(tenantId);

Hope this helps :)

sandeepsuvit commented 2 years ago

Closing this due to inactivity