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

How to use multiple databases (multitenancy) #147

Open
thailan opened this issue Oct 18, 2019 · 3 comments
Open

How to use multiple databases (multitenancy) #147

thailan opened this issue Oct 18, 2019 · 3 comments

Comments

@thailan
Copy link

thailan commented Oct 18, 2019

Hello , how can I use multiple databases for my project? For my current php application , I created a middleware where it gets subdomain and connects users to its database , so its subdomain based multitenant application. How can I achieve similar approach? Moleculerjs is is awesome , so I want to remake my application with moleculerjs. I use mysql, I believe I should use sequelize for my application. Thank you in advance for your help.

@thailan thailan changed the title How to use multiple database (multitenancy) How to use multiple databases (multitenancy) Oct 18, 2019
@epicbytes
Copy link

I had such experience recently, the whole point is to make a custom adapter and process the variables, at some point I collect the variables, middleware forwards them further and replaces the adapter, or rather creates more connections and adds an adapter with an identifier that the before hook accesses it and already works with another database through the adapter, maybe this is not the most beautiful way, but I could not find another.

@dragan-lalos
Copy link

Hello,

I do not want to open a new issue, and I hope my problem is similar to this one. If not, I will open a new issue.

The rule said:

Database per service

Moleculer follows the one database per service pattern. To learn more about this design pattern and its implications, check this article. For multiple entities/tables per service approach, check the FAQ.

Then you have the rule:

At the moment, Moleculer DB only supports one model per service.

The first rule makes sense because it follows the Database per service pattern; the second I can also understand.

The problem is that the first rule is not working. I tried to have DB per service, and in MongooseAdapter, I pass different DB URI, but Moleculer somehow always finds a wat to initiate one DB and put all documents into one DB.

adapter: new MongooseAdapter(process.env.MONGO_URI_RAW_DATA || "")

Does anyone has this problem? Any idea what is wrong?

@AndreMaz AndreMaz transferred this issue from moleculerjs/moleculer Nov 13, 2019
@AndreMaz
Copy link
Member

Hey @dragan-lalos . You might check #132 (comment) I think this is want you want

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

No branches or pull requests

4 participants