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));