• Guidelines for Using Collections and Indexes in MongoDB

    Although there is no formula to determine the optimal number of collections in a database, it’s advisable to stay away from putting a lot of disparate data into a single collection. Mixing an eclectic bunch together creates complexities for indexes. A good rule of thumb is to ask yourself whether you often need to query across the varied data set. If your answer is yes you should keep the data together, otherwise portioning it into separate collections is more efficient.

    Sometimes, a collection may grow indefi nitely and threaten to hit the 2 GB database size limit. Then it may be worthwhile to use capped collections. Capped collections in MongoDB are like a stack that has a predefi ned size. When a capped collection hits its limit, old data records are deleted. Old records are identifi ed on the basis of the Least Recently Used (LRU) algorithm. Document fetching in capped collection follows a Last-In-First-Out (LIFO) strategy.

    Its _id fi eld indexes every MongoDB collection. Additionally, indexes can be defi ned on any other attributes of the document. When queried, documents in a collection are returned in natural order of their _id in the collection. Only capped collections use a LIFO-based order, that is, insertion order. Cursors return applicable data in batches, each restricted by a maximum size of 8 MiB. Updates to records are in-place.

    MongoDB offers enhanced performance but it does so at the expense of reliability.

    Source of Information : NoSQL


0 comments:

Leave a Reply