Skip to content

Commit

Permalink
docs(schema): add more info and examples to Schema#indexes() docs
Browse files Browse the repository at this point in the history
Fix #10446
  • Loading branch information
vkarpov15 committed Aug 9, 2021
1 parent 99ae199 commit cdd4116
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1666,8 +1666,8 @@ Object.defineProperty(Schema, 'indexTypes', {
});

/**
* Returns a list of indexes that this schema declares, via `schema.index()`
* or by `index: true` in a path's options.
* Returns a list of indexes that this schema declares, via `schema.index()` or by `index: true` in a path's options.
* Indexes are expressed as an array `[spec, options]`.
*
* ####Example:
*
Expand All @@ -1680,6 +1680,17 @@ Object.defineProperty(Schema, 'indexTypes', {
* // [ { registeredAt: 1 }, { background: true } ] ]
* userSchema.indexes();
*
* [Plugins](/docs/plugins.html) can use the return value of this function to modify a schema's indexes.
* For example, the below plugin makes every index unique by default.
*
* function myPlugin(schema) {
* for (const index of schema.indexes()) {
* if (index[1].unique === undefined) {
* index[1].unique = true;
* }
* }
* }
*
* @api public
* @return {Array} list of indexes defined in the schema
*/
Expand Down

0 comments on commit cdd4116

Please sign in to comment.