I have the following MongoDB schema Item
- id
- title : string
- description : string
- num_views : number
- num_likes : number
- num_unlikes : number
- val_trending : number
- val_rating : number
- timestamp : number
val_trending is calculated based on the value of num_views, num_likes, num_dislikes, timestamp
val_rating is calculated based on the value of num_likes, num_dislikes, timestamp
I have to query Items based on num_views, val_trending or val_rating
i.e.
- Item.find ().sort ({ val_trending : -1 }).limit (20)
- Item.find ().sort ({ num_views : -1 }).limit (20)
num_views, num_likes and num_unlikes are updated when a user view, like or unlike an Item accordingly
val_trending is updated when a user view, like or unlike an Item
val_rating is updated when a user like or unlike an Item
That’s a lot of updating and that's what got me worried. I thought of indexing num_views, val_trending and val_rating for faster results. But this will also show down updates.
I will be querying Items several times every second and updates will occur more frequently as user might also like or unlike an Item after viewing an Item.
So, my question is: what sort of implementation (indexing) should I do in order to get the best performance?
Note: The DB will hold approximately 10K Items at start, and it will increase daily.
via ThunderRoid
No comments:
Post a Comment