I am using:
I am still in the development phase of my application and I am facing a potential problem ( WriteConflict
) using transactions in mongodb. My application gives the possibilities for users to add posts and to like posts. When liking a post, here what is happening on the back-end side :
Post
collectionLike
collectionPost
collectionUser
collectionUser
collectionNotification
collectionI'd say the average execution time is 1 second, so it means that for 1 second, I am locking :
Post
document User
documents I can see that as huge scalability problem, especially if a user has many popular posts that will often be liked by others.
What would you recommend me to do?
I don't think I can stop using transactions because if something goes bad during the execution of the function, I want to revert potential changes made to the DB
Thanks
Transactions are not required for this.
When updating counts, use $inc instead of read-modify-write (writing out the new value).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.