(node:551076) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. code example
Example 1: collection.ensureIndex is deprecated
mongoose.connect(dbURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: true,
})
Example 2: (node:3168) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. (Use `node --trace-deprecation ...` to show where the warning was created)
mongoose.set('useCreateIndex', true);
Example 3: (node:2496) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);