2 ms·
> Then adding an item to a cart means updating those fields. There probably is a way to do several similar updates atomically. Atomicity is document level, not
by elmigranto 9y ago
> Then adding an item to a cart means updating those fields. There probably is a way to do several similar updates atomically.
Atomicity is document level, not collection level. So you can't update multiple documents atomically. Or do you plan on having `{status: 'in-cart', cartOwner: 'customer-id' | null}` and single document for every stocked item (like 1k copies of the same book would be 1k db documents and you also have all those sold from before)?
> Another way is to use append-only collection
How does it help with overselling? To decide if it's okay to append, you have to know if current number of items is greater than 0 (don't forget to lock other clients out of appending this whole process, so they wait for you to finish).