kpfromer / nestjs-typegoose

Typegoose with NestJS
https://kpfromer.github.io/nestjs-typegoose/
MIT License
291 stars 73 forks source link

the options [connectionName] is not supported #57

Closed mmv08 closed 4 years ago

mmv08 commented 4 years ago

I'm trying to use multiple dbs in my app, however I get this error:

the options [connectionName] is not supported

Here is my usage of the typegoose module

@Module({
  imports: [
    TypegooseModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (config: ConfigService) => ({
        uri: config.get('MONGODB_URI_TODOS'),
        useNewUrlParser: true,
        useUnifiedTopology: true,
        useCreateIndex: true,
        connectionName: 'todos-db',
      })
    }),
    TypegooseModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (config: ConfigService) => ({
        uri: config.get('MONGODB_URI_USERS'),
        useNewUrlParser: true,
        useUnifiedTopology: true,
        useCreateIndex: true,
        connectionName: 'users-db',
      })
    }),
    ConfigModule,
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}

Versions:

"nestjs-typegoose": "^7.0.0",
"@nestjs/mongoose": "6.3.1",
"@typegoose/typegoose": "6.2.2",
mmv08 commented 4 years ago

Also I have this:

[ExceptionHandler] Nest can't resolve dependencies of the TodoModel (?). Please make sure that the argument todos-dbConnection at index [0] is available in the TypegooseModule context.
mmv08 commented 4 years ago

Ok so the problem was is I didn't notice that connectionName is also a top-level option in forRootAsync (also used in useFactory)

Screenshot 2020-01-29 at 01 14 49

Is this a documentation flaw or connectionName in useFactory meant to overwrite top-level one?

mmv08 commented 4 years ago

so after reading the source code it seems like a documentation flaw for me, I created a pr fixing the docs

kpfromer commented 4 years ago

Closing since the pr was merged.