Skip to content

Configuration - Database

The database access configuration is done through Mikro-orm via the MikroOrmModule.

app.module.ts
@Module({
  imports: [
    //...
   MikroOrmModule.forRoot({
      entities: [...CRUDEntities],
      driver: MongoDriver,
      dbName: "cli-app-db",
    }),
  ],
    //...
})
export class AppModule {}

Check out Mikro-orm's documentation for more info.

Multiple Databases

Each CrudServices takes an optional Mikro-orm instance that can be used to connect to another database. It will replace the global instance.

user.service.ts
const myOrm = await MikroORM.init({
  entities: [User],
  dbName: 'my-db-name',
  //...
});

@Injectable()
export class UserService extends CrudUserService<User> {
    constructor(/* ... */) {
        super( /* ... */, { orm: myOrm })
 }
    //..
}

Note

Splitting your database might prevent you from using the populate option in your queries.