Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multi tenant support #3

Open
mailaneel opened this issue Jan 20, 2018 · 2 comments
Open

add multi tenant support #3

mailaneel opened this issue Jan 20, 2018 · 2 comments

Comments

@mailaneel
Copy link
Contributor

Allow support of multi tenants

In settings

{
  // this could be specific to the adapters
  tenantStrategy: {
    // if these keys are not preset we throw validation error
    // and based on tenant strategy we might have to add these to every query we make to db
    tenantKeys: ['accountId'], // or (config, params) => ['accountId']

    // for mongo adapter return new db
    getDB: (config, params) => config.client.db(`${config.collection}-${params.accountId}`),

    // for mongo adapter return new collection
    getCollection: (config, params) => config.db.collection(`${config.collection}-${params.accountId}`),

    // for mongoose
    getModel: (config, params) => config.model,

    // if exists will override the adapter find or update the params and call adapter's find
    find: () => null
    // ... other methods
  }
}

And tenant strategies can be implemented by the adapters itself, example incase of mongoose, whether to use that as shardKey or use a separate collection or use a separate db

@ghost
Copy link

ghost commented Sep 6, 2019

Was there a solution or work around for this? If not, is there any guidance on how best to implement multi-database support within a service?

@yogesh-rs
Copy link

Any update on this issue? I have similar requirement- to dynamically connect to separate databases, based on some request parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants