I've a mongodb database which has multiple collections. There's one additional collection, which is more like a log of all events that happen in the system. I am wondering, when I've a large collection which is rarely used, is "_id" index of that collection also put into RAM when no operations happen on that collection ? Or it simply waits on the disk until a read operation in executed. My main concern is if this collection's size affects performance of other queries (due to size of the collection a few time larger than available RAM).
Asked
Active
Viewed 387 times
1 Answers
1
They'll be swapped out on an LRU basis.
Indexes do not have to fit entirely into RAM in all cases. If the value of the indexed field increments with every insert, and most queries select recently added documents; then MongoDB only needs to keep the parts of the index that hold the most recent or “right-most” values in RAM.
To ensure this index fits in RAM, you must not only have more than that much RAM available but also must have RAM available for the rest of the working set. The indexes and the working set must be able to fit in memory at the same time.
https://docs.mongodb.com/manual/tutorial/ensure-indexes-fit-ram/#indexing-right-handed