- 授权警告
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 (<anonymous>)
解决方法:
不把用户名和密码放在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;