Doubts about mongoose autoIndex

When the official document on

mongoose says that the autoIndex property is true, when the application starts, mongoose will automatically call ensureIndex for your schema to ensure that the index is generated. It is good to use this in the development environment, but it is not recommended in the production environment. In that case, how to build the index, do you have to manually use mongo shell to build the index one by one?

Mar.20,2021

creating an index is an one-time task, and manual creation is the best choice in mongo shell. Why do you say "isn't it"?
this is not just a question of how many times it will be executed, when it will be executed, and whether it will affect the production environment. To understand that the indexing process is a great consumption to the database, the foreground index locks all CRUD operations on the entire collection, while the background index is not locked directly, but it still consumes a lot of CPU and IO to read the document and modify the index. Either way, it is possible to consume a lot of time and resources (such as creating an index on a larger collection). This is also the reason why mongoose is not recommended for use in production environments.
production environment requires stability, convenience is secondary. When it comes to "stability", it is bound to be "convenience" to make concessions.

Menu