1. 程式人生 > 其它 >mongoose報錯處理DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead

mongoose報錯處理DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead

技術標籤:MongoDBmongoose

今天遇到mongoose有兩個報錯,導致npm在docker中一直無法正常啟動

第一個報錯:
[egg-scripts] Got error when startup:
[egg-scripts] (node:64) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

在options中新增

useUnifiedTopology: true,

第二個報錯:
[egg-scripts] (node:48) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

在options中新增

useCreateIndex: true

下圖紅圈部分就是新增的部分:
在這裡插入圖片描述