Open2

NestJS

offshoreropeoffshorerope

NestJSとMongodbの接続

基本は下記動画で設定

MongodbのURLを.envを使用して設定したい場合は以下に変更

.env
DATABASE_URL="mongodb+srv://xxxxxxxxxx:xxxxxxxxxx@cluster1.hpzl4.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
src/app.module.ts
import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { MongooseModule } from "@nestjs/mongoose";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";

@Module({
  imports: [
    ConfigModule.forRoot(),
    MongooseModule.forRoot(
      String(process.env.DATABASE_URL),
    ),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}