'Mongodb huge date index size
I have a mongodb database storing documents with a publication date and an end date. For my request i need to create an index with both on those dates.
My collection size is about 17GB for a total of 6 Millions documents.
When i create my index, the index size is about 600MB ... but when i use it intensively, the size get up to 70GB ... 6 times more than the documents themselves oO
Am i doing something wrong ? Is there some special considerations with date fields ? (I only have problem with date indexes).
Note: I suspected my dates to be "too precises" to be indexed, so i rounded them to the nearest hour ... without any index size decrease.
Solution 1:[1]
Okay i've found the reason of this really strange bug. I am putting it here since it can happens to others.
- I'm using moment.js for managing dates on node.js
- I'm using mongodb driver directly (not mongoose)
- (I forgot to precise it in my question), i make an update on my dates in my intensive scripts.
- I update those dates with a moment object instead of a pure javascript date making mongodb try to index every bit of subpath i think which is responsible of this huge index size.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Poyoman |


