Automattic / Automattic/mongoose
Proposal to Set autoIndex Parameter to false by Default
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 27.5k
- Forks
- 4k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 35
Description
### Prerequisites
- [x] I have written a descriptive issue title
- [x] I have searched existing issues to ensure the issue has not already been raised
### Issue
I’d like to propose setting the `autoIndex` parameter in Mongoose schemas to **false** by default. While `autoIndex` is a great feature for development environments, enabling it by default can lead to unintended consequences in production environments.
According to the [Mongoose documentation](https://mongoosejs.com/docs/guide.html#autoIndex), enabling `autoIndex` by default is described as being beneficial for development but _"not recommended for production since index creation can cause significant performance impact."_ Unfortunately, developers often overlook this recommendation, leading to production issues when autoIndex is not explicitly disabled.
This concern has been raised by developers on platforms such as [StackOverflow](https://stackoverflow.com/questions/20906679/mongoose-call-ensureindex-on-startup-but-its-not-recommended-so-why-its-defa), highlighting confusion and challenges around the default behavior of `autoIndex`. Since Mongoose sets it to true by default, many users forget about it until it causes problems in production environments.
Index creation can be slow, especially for large collections, and may exceed the default `maxTimeMS` (60 seconds). This can result in failures of Mongoose operations that depend on autoIndex, while the background index creation continues on MongoDB. Applications that restart after encountering these errors often re-trigger the `createIndex` requests, compounding the performance problems or even causing application downtime.
Setting `autoIndex` to false by default would nudge users toward a safer, production-appropriate configuration. Developers can still enable it explicitly for development environments as needed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start with the linked Mongoose autoIndex documentation and the schema configuration that defines this default; check how the change affects development overrides and production index creation. Done means the default is false, explicit opt-in remains possible, and the relevant behavior and documentation are updated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100