嵌套服务器未连接到MongoDB云UnhandledPromiseRejectionWarning: MongoPars



我的NestJS后端需要连接到mongodb云,我从这里遵循文档

终端出现以下错误:

(node:6920) UnhandledPromiseRejectionWarning: MongoParseError: URI malformed
at new ConnectionString (D:growthquizbackendquizbackendnode_modulesmongodb-connection-string-urlsrcindex.ts:113:13)
at Object.parseOptions (D:growthquizbackendquizbackendnode_modulesmongodbsrcconnection_string.ts:249:15)
at new MongoClient (D:growthquizbackendquizbackendnode_modulesmongodbsrcmongo_client.ts:332:22)
at D:growthquizbackendquizbackendnode_modulesmongooselibconnection.js:785:16
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (D:growthquizbackendquizbackendnode_modulesmongooselibconnection.js:782:19)
at Mongoose.createConnection (D:growthquizbackendquizbackendnode_modulesmongooselibindex.js:275:10)
at Function.<anonymous> (D:growthquizbackendquizbackendnode_modules@nestjsmongoosedistmongoose-core.module.js:60:63)
at Generator.next (<anonymous>)
at D:growthquizbackendquizbackendnode_modules@nestjsmongoosedistmongoose-core.module.js:20:71
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6920) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:6920) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, 
promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我的app模块代码:

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UsersModule } from './users/users.module';
import {MongooseModule} from '@nestjs/mongoose'
@Module({
imports: [UsersModule,MongooseModule.forRoot('mongodb+srv://icfoajscijwq90j@cluster0.8rxa2.mongodb.net/nest-js-db?retryWrites=true&w=majority')],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}

我仔细检查了我的用户名和密码,但它们是正确的,是否有必要对它们进行编码,或者为什么会出现错误,请解释一下。

确保您的用户名密码和在URI连接字符串中没有任何非法字符.

如果用户名或密码包含以下字符:

: / ? # [ ] @

这些字符必须使用百分比编码进行转换。

基于他们的文档:https://docs.mongodb.com/manual/reference/connection-string/

最新更新