#Nest.js + mikro-orm with named DB connections

1 messages · Page 1 of 1 (latest)

hoary halo
#

Hello everyone,
Since 6.2.0 mikro-orm supports mssql.
In our project (in some services) we use both mongo & mssql.
I'm trying to configure the project to work with both, but failing...
Decided to make a step back and have only mongo, but using named connection (AKA contextName) and as soon as I add it the project fails with the following error:

core/injector/injector.js:254
throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef, { id: wrapper.id });
                  ^
Error: Nest can't resolve dependencies of the MikroOrmMiddleware (?). Please make sure that the argument MikroORM at index [0] is available in the MikroOrmCoreModule context.

Potential solutions:
- Is MikroOrmCoreModule a valid NestJS module?
- If MikroORM is a provider, is it part of the current MikroOrmCoreModule?
- If MikroORM is exported from a separate @Module, is that module imported within MikroOrmCoreModule?
  @Module({
    imports: [ /* the Module containing MikroORM */ ]
  })

Has anyone ever tried to have 2 connections at the same time with mikro-orm?
Thanks in advance and feel free to ask for snippets of code if needed.

burnt vine
#

@hoary halo Did you find a fix ? I have the same issue

hoary halo
#

Hi @burnt vine yes, I was able to configure the app so it works with both connections.
If you want an example- ping me tomorrow and I’ll post details here

burnt vine
#

That would be nice ! Thanks 🙂

burnt vine
#

@hoary halo I'm still interested in an exemple 😉

hoary halo
burnt vine
#

Thanks ! I see that you are using registerRequestContext: false , when doing this, do you also call MikroOrmModule.forMiddleware() ? @hoary halo

hoary halo
#

I didn’t need that middleware for now but yes, if you need it - you will have to initiate forMiddleware manually.

burnt vine
#

Ok thanks !
Do you use the CLI to create migrations ? How do you do it ?