Schema.prototype.indexes()

Returns:
  • «Array» list of indexes defined in the schema

Returns a list of indexes that this schema declares, via schema.index() or by index: true in a path’s options.

Example:

  1. const userSchema = new Schema({
  2. email: { type: String, required: true, unique: true },
  3. registeredAt: { type: Date, index: true }
  4. });
  5. // [ [ { email: 1 }, { unique: true, background: true } ],
  6. // [ { registeredAt: 1 }, { background: true } ] ]
  7. userSchema.indexes();