nestjs 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:2496) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

/*As of this edit, Mongoose is now at v5.4.13. Per their docs, these are the fixes for the deprecation warnings..*/
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);