kindagoose icon indicating copy to clipboard operation
kindagoose copied to clipboard

Missing connectionFactory option when configuring KindagooseModule

Open ghmendonca opened this issue 1 year ago • 1 comments

Thanks for this library, it's amazing and much better than the NestJS default one.

One thing that is missing is the ability to get the connection and do something with it, in my case I'm applying a custom plugin that I've created, and with this I achieve a "global" plugin for all my models.

With @nestjs/mongoose I could do this:

MongooseModule.forRootAsync({
  imports: [ConfigModule],
  useClass: MongooseConfigService,
}),

And in my MongooseConfigService class, I have:

@Injectable()
export class MongooseConfigService implements MongooseOptionsFactory {
  constructor(private config: ConfigService<EnvironmentVariables>) {}

  async createMongooseOptions(): Promise<MongooseModuleOptions> {
    return {
      uri: this.config.getOrThrow('MONGO_URL'),
      connectionFactory: (connection) => {
        connection.plugin(nanoidPlugin);
        return connection;
      },
    };
  }
}

Would be nice to have something similar in kindagoose

ghmendonca avatar Oct 22 '24 08:10 ghmendonca

Greetings! I will consider this a little bit later, now overflowed by primary tasks...

findingtheconcept avatar Oct 22 '24 13:10 findingtheconcept