This is wrong. Imagine 2 users like the same post concurrently, then 2 transactions will try to increment likesCount of the same document => one of them will be cancelled due to the transaction ACID policy. I pointed that i use event queues, the system is large scale…I want like for upserts to be able to check whether an operation, e.g. the 3 operation in the batch which is unlike to check whether the deletion has actually removed a document so that later in another bulk to incr/decr the correspondign counters.
I think mongdb team will not add this to the bulkWrite because for efficiency reasons. But this makes impossible to make this entire operation in two bulk jobs.
I think i found some workaround which i am not sure whether it is efficient for large amount of likes imagine you have 1k like operations and each post has 10k likes. The idea is to count the number of likes for each post in an aggegation pipeline and then to use $merge to update the likesCount in the metadata collection. What do you think? Is this going to be efficient?