inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

탄탄한 백엔드 NestJS, 기초부터 심화까지

NestJS와 DB 연결하기, 환경 변수 설정

mongoose 6.0 부터는 영상의 옵션 설정을 안 해도 된다고 하네요

494

태기
2

해당 영상보고 실습하고 있는데 영상의 몽구스 옵션 부분의 타입 유추가 안 되고  또 실행하면 useFindAndModify, useCreateIndex 옵션을 지원하지 않는다는 에러가 뜨길래 찾아보니 몽구스 6.0 부터는 해당 영상의 옵션과 똑같이 설정한 것처럼 작동한다고 해당 옵션을 제거하라고 하네요!

몽구스 설정에서 에러 나시는 분들은 package.json에서  @nestjs/mongoose 버전이 8 이상, mongoose 버전이 6 이상인지 확인하시고 맞으시면 해당 옵션 제거하시면 됩니다요!

https://mongoosejs.com/docs/migrating_to_6.html#no-more-deprecation-warning-options

mongoose @nestjs/mongoose

답변 2

1

천명기

저는 환경변수를 *.module.ts 파일에서 읽어오지 못하는 문제가 있었습니다.

아래와 같은 방법으로 해결했습니다. 참고가 되실지 모르겠습니다.

@Module({
	imports: [
                // expandVariables: env 파일의 변수들 간의 interpolation 사용여부
		ConfigModule.forRoot({ isGlobal: true, expandVariables: true }),
		// async로 변경하고
		MongooseModule.forRootAsync({
			// ConfigService 주입
			inject: [ConfigService],
			// 주입 받은 ConfigService의 get 으로 불러온 환경변수 가져오기
			useFactory: async (configService: ConfigService) => ({
				uri: configService.get('MONGODB_URI'),
			}),
		}),
		CatsModule,
	],
	controllers: [AppController],
	providers: [AppService],
})
export class AppModule implements NestModule {
        // ...code
}

0

윤상석

감사합니다. 김은택님! 👍