I’m using MongoDB and MySQL for different aspects of an e-commerce site.
One of the features is ‘bidding’. The price goes up with each bid.
There are several ways I could do this, such as having a single column that updates the ‘price’ or I could have another column that simply adds prices and I can get the latest price based on the date, requiring an order by. Also, each new price, will be based off the current high price, so I’ll need to know the current high price.
I’d like to keep this in the MongoDB portion, but not sure what best way to handle this.
Any suggestions would be great!
Thank you!
You can atomically update documents in mongodb, there’s an $inc operator, so you can atomically update a document’s “max price” while also $pushing the last bidder, the date, and the price increase to an array, for example. This way you’ll never be in danger of having an inconsistent auction document. Using safe mode for writes is necessary too.
Splitting bids into separate documents which you then assemble to find the current price is another solution. It really depends on how much state you’re tracking with the bids.