解決 mongoose DeprecationWarning 錯誤導致數據庫連接不成功


mongoose 版本低提示錯誤為:

DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

通常升級 mongoose 就可以解決:

npm install mongoose

 


 

 

連接數據庫參數缺失提示錯誤:

DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.

通常根據錯誤信息提示,將 useNewUrlparser 添加到 mongoose.connect 即可:

// db
const db = "mongodb://localhost:27017/blog";
mongoose.Promise = global.Promise
mongoose.connect(db, { useNewUrlParser: true }).then(() => console.log('Database Successful!')).catch((err) => console.log(err));

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM