Why does MongoDB slow down on writes when I add indexes?
Every index adds overhead to writes because MongoDB has to update each index. Indexes are a tradeoff: faster reads, slower writes. Do not index every field; index only the queries you actually run.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Mongoose Indexes: Types and When to Use Them
Single field, unique, compound, text (full-text), geospatial (2dsphere), and TTL (auto-expire). Each suits a different query pattern or constraint.
When you query on multiple fields together. For example, (fromUserId, toUserId) for connection requests. Put the field you filter by first, then the field you sort by. Use explain() to verify the index is used.
An index with expireAfterSeconds that auto-deletes documents after a timeout. Use for sessions, tokens, or logs that should expire. Example: schema.index({ createdAt: 1 }, { expireAfterSeconds: 3600 }).
Still have questions?
Browse all our FAQs or reach out to our support team
