0

I'm currently developing a system that will allow users to post content to a facebook-like 'wall'. Part of this system will allow users to 'like' the content of other users, content can also be 'unliked' to remove the user's like.

The likes are being modelled as an array of user IDs in the post document, what I would like to be able to do is simply 'toggle' the existence of an ID in the array, i.e. if the user ID exists in the array remove it, otherwise add it, but in an atomic way so ideally in one query so that I can be sure the data remains consistent..

I'm aware of the bulk-write API, however after doing some research it seems the batch writes aren't committed in an atomic way, so consistency guarantees still cannot be made.

So am I correct in saying this isn't something that is possible with the current version of MongoDB? I'm using the .NET driver but as far as I'm aware it supports everything.

Astronought
  • 405
  • 5
  • 24
  • https://stackoverflow.com/questions/9459789/how-to-toggle-a-boolean-field-in-one-document-with-atomic-operation 2nd answer – D. SM Jan 25 '21 at 02:58
  • Here is a similar post: [How to toggle an element in a MongoDB Array](https://stackoverflow.com/questions/51618537/how-to-toggle-an-element-in-array-in-mongodb/62380969#62380969). – prasad_ Jan 25 '21 at 07:08

0 Answers0