MongoDB is a NoSql database. In MongoDB data is stored in the form of collections. In case of large applications there is a chance that size of the collection becomes more which will reduce the performance. Because when the collection size consumes all the RAM space of the machine , then it needs to use secondary memory (hard-disk) which will take more time in completing the tasks. There are many patterns in mongodb.
A proper design modelling of database is required before starting an application development. Let’s get into this right away :) .
Let’s suppose in our project we have a collection and its size is increasing rapidly but only some data is used frequently. Doing any operation on this large collection will definitely consume more time. So , if we observe this carefully , “ only some data is used frequently “ . Means there is a lot of extra data which is used very less frequently in the collection.This pattern is all about separating the less frequently used data.
Let’s take some example where we can implement this ,
In a shopping application for each product there can be many reviews. Storing all the review in the cart collection makes it larger. Instead we can store the recent 10 or 15 reviews in the cart collection and create a new collection for other reviews. If the user wants more reviews then we will bring it from new collection which is created.
I have implemented in my personal project . I have stored only the recent 5 histories of the patient in the Patient collection and all histories of the patient are stored in a new collection with the patient id.