-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Prerequisites
- I have written a descriptive issue title
- 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, 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, 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.