这个错误来自哪里?我没有在任何地方的 Nodejs 应用程序中使用 ensureIndex
或 createIndex
。我正在使用 yarn 包管理器。
这是我在 index.js
import express from 'express';
import path from 'path';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import Promise from 'bluebird';
dotenv.config();
mongoose.Promise = Promise;
mongoose.connect('mongodb://localhost:27017/bookworm', { useNewUrlParser: true });
const app = express();
最佳答案
问题在于 mongoose仍然使用 collection.ensureIndex 并且应该在不久的将来由他们更新。要摆脱该消息,您可以使用 package.json 中的 5.2.8 版本降级(并删除任何缓存,最后的手段是卸载它并使用 npm install mongoose@5.2.8 安装它):
"mongoose": "^5.2.8"
编辑: 截至本次编辑,Mongoose 现在是 v5.4.13。根据他们的文档,这些是弃用警告的修复...
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);
Replace update() with updateOne(), updateMany(), or replaceOne()
Replace remove() with deleteOne() or deleteMany().
Replace count() with countDocuments(), unless you want to count how many documents are in the whole collection (no filter). In the latter case, use estimatedDocumentCount().
关于node.js - ( Node :63208) DeprecationWarning: collection. ensureIndex 已弃用。请改用 createIndexes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51960171/