mongoose報錯處理DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead
阿新 • • 發佈:2020-12-12
今天遇到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
下圖紅圈部分就是新增的部分: