在 Nest 中使用 mongodb 数据库进行数据库连接时提示警告:
(node:79342) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
在 app.module.ts
文件中使用 MongooseModule 时添加 { useNewUrlParser: true }
配置即可。
例如:
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MongooseModule } from '@nestjs/mongoose';
@Module({
imports: [MongooseModule.forRoot('mongodb://localhost/nest', { useNewUrlParser: true })],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}