MongoParseError:无效的连接字符串 [英] MongoParseError: Invalid connection string

查看:253
本文介绍了MongoParseError:无效的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此代码连接MongoDB数据库,但是在运行它时出现错误(请参见代码后的以下错误)。最初的错误是通过添加 useNewUrlParser:true 来解决的,但即使在此之后,我仍然遇到更多错误。我正在使用MongoDB 4.0.1版。有人知道如何解决此错误吗?

I am trying to connect MongoDB database with this code but when running it I get the error (see the error below after the code). The initial error was in the line where it was resolved by adding useNewUrlParser: true but even after this I still get more errors. I am using MongoDB version 4.0.1. Does anybody know how to resolve this error?

mongoose.connect('User://localhost:27017/User',{ useNewUrlParser: true })

运行此代码时出错:


(节点:11068)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:3):MongoParseError:无效的连接字符串
(节点:11068)[DEP0018] DeprecationWarning:未处理的承诺不推荐使用。将来,未处理的承诺拒绝将以非零退出代码终止Node.js进程。

(node:11068) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): MongoParseError: Invalid connection string (node:11068) [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.


推荐答案

使用'mongodb:// localhost /'
代替用户,我遇到了同样的问题。

Instead of User, use 'mongodb://localhost/' I had the same problem.

这篇关于MongoParseError:无效的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆