Hi @Imran_Azad ,
In that case it sounds like you may have the benefit of splitting the data into a “latest” collection and a history collection.
In the latest collection you will store the most recent version and have it queried and indexed by id.
While the history collection will receive the privious state. So essentially an update is a “transaction” of delete => insert new with same _id => insert old.
If updates are so frequent and the critical path is the write and not the read you may consider the following alternative:
Insert a new version into the main collection keeping the history in the same one (you may offload the history as a batch process)
In this design I Invision the collection as follows:
{
_id : some generic unique,
ItemId : "xyz" ,
timestamp : latest timestamp
...
}
The index for lookup by id is now { itemId: 1, timestamp: -1}
When you lookup by id you do:
collection.findOne({itemId : "xyz"}).sort({timestamp : -1})
This will get only latest version.
Thanks
Pavel