暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

链接mongodb数据库遇到的错误处理

原创 黄舒琪 2021-07-08
1326

授权警告

Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.

解决方案:

使用mongoose.connect链接时 添加 useMongoClient:true 参数

由于密码复杂 包含百分号 @ 符号等特殊字符 造成的URI错误比如:
mongodb://usename:Ca!!6Xei#5zidae$6aer%ai7u_Yo@4ee@hots:prot/database报错
URIError: URI malformed at decodeURIComponent ()
解决方法:

不把用户名和密码放在uri,而是像传对象那样传进去,想这样

var db_url = mongodb://${host}:${port}/${database}; // 链接mongodb mongoose.connect(db_url,{user:username,pass:password,useMongoClient:true})
其他PORT=7070指定启动端口 &表示进程守护
PORT=7070 node app.js &
关于内部端口的处理代码

//默认是用8080端口,使用process.env.PORT 可以获取传进来的端口号 var port = process.env.PORT || 8080;

最后修改时间:2021-07-08 13:42:56
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论