(node:30744) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. (Use `node --trace-deprecation ...` to show where the warning was created) code example

Example 1: (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 2: (node:2736) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

mongoose.connect(
  url,
  {useCreateIndex: true },
  () => {
    console.log("MongoDB is connected!");
  }
);