Skip to content

Commit

Permalink
Merge pull request #13377 from Automattic/IslandRhythms/gh-13287
Browse files Browse the repository at this point in the history
add `excludeIndexes` to the guide schema options
  • Loading branch information
vkarpov15 committed May 3, 2023
2 parents 97450e0 + 30e7405 commit 0b17caf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ Valid options:
- [capped](#capped)
- [collection](#collection)
- [discriminatorKey](#discriminatorKey)
- [excludeIndexes](#excludeIndexes)
- [id](#id)
- [_id](#_id)
- [minimize](#minimize)
Expand Down Expand Up @@ -626,6 +627,30 @@ const doc = new PersonModel({ name: 'James T. Kirk' });
doc.type; // 'Person'
```

<h2 id="excludeIndexes"><a href="#excludeIndexes">option: excludeIndexes</a></h2>

When `excludeIndexes` is `true`, Mongoose will not create indexes from the given subdocument schema.
This option only works when the schema is used in a subdocument path or document array path, Mongoose ignores this option if set on the top-level schema for a model.
Defaults to `false`.

```javascript
const childSchema1 = Schema({
name: { type: String, index: true }
});

const childSchema2 = Schema({
name: { type: String, index: true }
}, { excludeIndexes: true });

// Mongoose will create an index on `child1.name`, but **not** `child2.name`, because `excludeIndexes`
// is true on `childSchema2`
const User = new Schema({
name: { type: String, index: true },
child1: childSchema1,
child2: childSchema2
});
```

<h2 id="id"><a href="#id">option: id</a></h2>

Mongoose assigns each of your schemas an `id` virtual getter by default
Expand Down

0 comments on commit 0b17caf

Please sign in to comment.