返回 AiToEarn
db-mongo.module.ts
根目录 / project / aitoearn-electron / server / src / db / db-mongo.module.ts
1 /*
2 * @Author: nevin
3 * @Date: 2022-09-23 18:00:51
4 * @LastEditTime: 2025-01-15 14:20:46
5 * @LastEditors: nevin
6 * @Description:
7 */
8 import { Global, Module } from '@nestjs/common';
9 import { ConfigModule, ConfigService } from '@nestjs/config';
10 import { MongooseModule } from '@nestjs/mongoose';
11 import mongoConfig from '../../config/mongo.config';
12 import { Id, IdSchema } from './id.schema';
13 import { IdService } from './id.service';
14
15 @Global()
16 @Module({
17 imports: [
18 ConfigModule.forRoot({
19 load: [mongoConfig], // 加载配置
20 }),
21 MongooseModule.forRootAsync({
22 imports: [ConfigModule], // 数据库配置项依赖于ConfigModule,需在此引入
23 inject: [ConfigService],
24 useFactory: (configService: ConfigService) =>
25 configService.get('MONGO_CONFIG'),
26 }),
27 MongooseModule.forFeature([
28 // 挂载实体
29 { name: Id.name, schema: IdSchema },
30 ]),
31 ],
32 providers: [IdService],
33 exports: [IdService],
34 })
35 export class DbMongoModule {}
36
36 lines TYPESCRIPT