MongoDB use-case inventory
I am building an online retail store that has a fixed amount of clothes to sell obviously before its marked "sold-out". Assuming the traffic might get really high with clothes and other items selling out rapidly, I wanted to use MongoDB to track the inventory. However is this the best use-case for MongoDb.
How does MongoDB handle multiple updates to a single document.
In my case say there are 10 t-shirts, and 11 people come to the smae page to buy it. Now as there buying it, I check if t开发者_Python百科he inventory is avaiable then perform an update decreasing the count. Will mongoDB queue the operations so that the update from a previous user is made and then the count is called?
MongoDB has a findandmodify function that will allow you to do an atomic update.
http://www.mongodb.org/display/DOCS/findAndModify+Command
It should allow you to do
Speaking strictly to the 'use case' question, I think inventory management is something you'd traditionally look toward a transactional RDBMS for. But it's not to say that MongoDB couldn't or wouldn't work fine (as others have already posted), just that it's not to my mind one of the hallmark features.
You might consider partitioning your business logic into two sections: site visits (presumably very high) and purchases/transactions (presumably some very small percentage of visits). Then consider the benefits of distributed content delivery for the former, and transactional behavior for the latter.
精彩评论