Nest server not connecting to MongoDB cloud UnhandledPromiseRejectionWarning: MongoParseError: URI malformed

Nest server not connecting to MongoDB cloud UnhandledPromiseRejectionWarning: MongoParseError: URI malformed

我的 NestJS 后端需要连接到 mongodb 云,我遵循了 here

中的文档

终端中出现以下错误:

    (node:6920) UnhandledPromiseRejectionWarning: MongoParseError: URI malformed
    at new ConnectionString (D:\growth\quizbackend\quizbackend\node_modules\mongodb-connection-string-url\src\index.ts:113:13)
    at Object.parseOptions (D:\growth\quizbackend\quizbackend\node_modules\mongodb\src\connection_string.ts:249:15)
    at new MongoClient (D:\growth\quizbackend\quizbackend\node_modules\mongodb\src\mongo_client.ts:332:22)
    at D:\growth\quizbackend\quizbackend\node_modules\mongoose\lib\connection.js:785:16
    at new Promise (<anonymous>)
    at NativeConnection.Connection.openUri (D:\growth\quizbackend\quizbackend\node_modules\mongoose\lib\connection.js:782:19)
    at Mongoose.createConnection (D:\growth\quizbackend\quizbackend\node_modules\mongoose\lib\index.js:275:10)
    at Function.<anonymous> (D:\growth\quizbackend\quizbackend\node_modules\@nestjs\mongoose\dist\mongoose-core.module.js:60:63)
    at Generator.next (<anonymous>)
    at D:\growth\quizbackend\quizbackend\node_modules\@nestjs\mongoose\dist\mongoose-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.

我的应用模块代码:

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://samiurkhan:%1@cluster0.8rxa2.mongodb.net/nest-js-db?retryWrites=true&w=majority')],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

我仔细检查了我的用户名和密码,但它们是正确的,是否需要对它们进行编码,或者为什么会抛出错误,我们将不胜感激。

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

If the username or password includes the following characters:

: / ? # [ ] @

those characters must be converted using percent encoding.

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