【问题标题】:"MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://""when tried to connect with a .env file\"MongoParseError: Invalid scheme, 预期连接字符串以 \"mongodb://\" 或 \"mongodb+srv://\"\" 开头,当尝试连接 .env 文件时
【发布时间】:2022-09-25 21:09:32
【问题描述】:

我一直在尝试将我的项目与 mongoose 连接,当我直接在 mongoose.connect() 函数中使用 URL 时,它连接成功。但是在我创建一个 .env 文件并使用它而不是 mongoose.connect() 函数中的链接后,我收到一条错误消息,指出 \"MongoParseError: Invalid scheme, expected connection string to start with \"mongodb://\" or \"mongodb+srv://\"\"

    标签: mongodb mongoose


    【解决方案1】:

    我有同样的问题。 如果我尝试使用原始字符串:“mongodb://localhost:27017/”, 一切正常。但是使用 dotenv 我得到了同样的错误。 我重新安装了所有 npm 依赖项,但错误仍然存​​在。

    【讨论】:

      猜你喜欢
      • 2020-12-09
      • 2021-05-19
      • 2019-07-10
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多