- 授權警告
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 參數(shù)
- 由于密碼復雜 包含百分號 @ 符號等特殊字符 造成的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 &
關于內(nèi)部端口的處理代碼
//默認是用8080端口,使用process.env.PORT 可以獲取傳進來的端口號
var port = process.env.PORT || 8080;