1

I am building a web app with MongoDB. When the app connects to my database, the autoIndex flag is set to true by default. However, according to the documentation it's not recommended using it in production.

The autoIndex flag rebuilds indexes and it affects performance. And this is fine. But why and when would I need to rebuild my indexes?

My database consists of a few documents, each one has one or more indexes. If I add a new property (with an index) to the existing schema, or create a new document schema with indexes, do I need to rebuild my indexes then, or MongoDB will automatically create indexes for new properties that need it? This part of the lifecycle is not very well explained or I haven't found a good resource about it. But I don't want to go live with my app without being fully aware of the detailed autoIndex behaviour.

Łukasz Szkup
  • 117
  • 1
  • 9
  • Index in MongoDB must be manually created to align with your queries. However once created, you don't need to "recreate" it to maintain performance, it will be maintained as part of a normal database operation. I suggest you see [Indexes](https://docs.mongodb.com/manual/indexes/) and [Indexing Strategies](https://docs.mongodb.com/manual/applications/indexes/) to learn more about how indexes are used and defined in MongoDB. – kevinadi May 08 '18 at 06:24

0 Answers0