Why are my mongodb indexes so large

mongodb

Solution

The index size is determined by the number of documents being indexed, as well as the size of the key (compound keys store more information and will be larger). In this case, the _id index divided by the number of documents is 40 bytes, which seems relatively reasonable.

If you run db.collection.getIndexes(), you can find the index version. If {v : 0}, the index was created prior to mongo 2.0, in which case you should upgrade to {v:1}. This process is documented here: http://www.mongodb.org/display/DOCS/Index+Versions

Problem

I have 57M documents in my mongodb collection, which is 19G of data. My indexes are taking up 10G. Does this sound normal or could I be doing something very wrong! My primary key is 2G. ``` { "ns" : "myDatabase.logs", "count" : 56795183, "size" : 19995518140, "avgObjSize" : 352.0636272974065, "storageSize" : 21217578928, "numExtents" : 39, "nindexes" : 4, "lastExtentSize" : 2146426864, "paddingFactor" : 1, "flags" : 1, "totalIndexSize" : 10753999088, "indexSizes" : { "_id_" : 2330814080, "type_1_playerId_1" : 2999537296, "type_1_time_-1" : 2344582464, "type_1_tableId_1" : 3079065248 }, "ok" : 1 } ```

Original source