Yes, there is a way. You can use totalIndexSize() or stats() to check the size of the index
> db.collection.totalIndexSize() > 1073741824 > db.collection.stats() > { "ns" : "collection.test", "count" : 100006, "size" : 72104, "avgObjSize" : 4506.5, "storageSize" : 688128, "numExtents" : 3, "nindexes" : 1, "lastExtentSize" : 524288, "paddingFactor" : 1.0170000000000319, "systemFlags" : 1, "userFlags" : 0, "totalIndexSize" : 1073741824, "indexSizes" : { "_id_" : 1073741824 }, "ok" : 1
Both return the size of the collection index in bytes. In the above example, the index size is 1GB .
UPDATE
To find the total index size of the entire database, you can use stats()
> db.stats() { "db" : "test", "collections" : 10, "objects" : 5909990, "avgObjSize" : 2888.31186440677965, "dataSize" : 170123304, "storageSize" : 14745603499, "numExtents" : 17, "indexes" : 8, "indexSize" : 1073741824, "fileSize" : 50331648, "nsSizeMB" : 163453, "ok" : 1 }
Now you can compare indexSize with the RAM of the machine to check if the index is suitable in memory or not. And you can increase the size of RAM to accommodate the full index.
Hope this helps