News for hackers. Stuff that matters.
Re:MongoDB gets support for multi-document ACID transactions by fnayr on Thursday February 15, 2018 @01:43PM (#16386417)
Video games storing player data are a great example of nonrelational data. I'm intending on writing a blog post after I finish my game detailing the structure of data I store and why it was so perfect for mongodb.
Re:MongoDB gets support for multi-document ACID transactions by mustardo on Thursday February 15, 2018 @06:28PM (#16388698)
On the surface it sounds like you might have a case for Mongo, lookout for scenarios like...

* Trading in game items between two users (needs multi document atomic locks if you don't want duplicate or lost items) assuming your "schema" is a document per user

* You want to rename or restructure an attribute in the future, with no schema it's not possible change migrate data easily without writing ad hoc code (maybe you can use third party tools) or changing queries to expect data in multiple "schemas" which quickly gets painful

Good Luck!

Re:MongoDB gets support for multi-document ACID transactions by mygo on Thursday February 15, 2018 @06:46PM (#16388803)
> You want to rename or restructure an attribute in the future, with no schema it's not possible change migrate data easily without writing ad hoc code (maybe you can use third party tools) or changing queries to expect data in multiple "schemas" which quickly gets painful

You can have schemas with MongoDB. There are various libraries to facilitate database design by schema specification.

Also renaming or restructuring your data is not necessarily an easy task with SQL. The nature of a database dictates that how good it works for your application depends on up to how well thought-out your schema is. Having to change your schema around is tasking. One of the reported advantages of document stores when they were becoming trendy was that it was easy to change your schema since your schema is essentially determined and regulated at the application layer.

Also MongoDB has ACIDic transactions now (freaking finally) so if it’s as-advertised then I feel like half of your argument is not really a strong one any more.

Re:MongoDB gets support for multi-document ACID transactions by chris_wot on Thursday February 15, 2018 @10:11PM (#16389568)
If you need a schema, then go with an RDBMS.
Re:MongoDB gets support for multi-document ACID transactions by fnayr on Thursday February 15, 2018 @06:34PM (#16388747)
Yes players can sell items to other players, so that's the one place so far I've needed to worry about atomicity, but even mongodb docs give examples with how to deal with something like that: https://docs.mongodb.com/manual/tutorial/perform-two-phase-c...

So yes, it's annoying for a very small % of what I'm doing, but 99% of my updates/writes are within a single document, so I find it very nice for development.

Re:MongoDB gets support for multi-document ACID transactions by drmirror on Thursday February 15, 2018 @06:44PM (#16388795)
About the first use case, well it turns out MongoDB just introduced multi-document transactions today.
Re:MongoDB gets support for multi-document ACID transactions by mustardo on Thursday February 15, 2018 @07:05PM (#16388894)
If only someone had posted that information to HN
Re:MongoDB gets support for multi-document ACID transactions by javiermaestro on Thursday February 15, 2018 @03:10PM (#16387153)
Please do, because I'm interested in seeing how non-relational it is... I truly believe it has to be otherwise, so I'd love to read your findings!
Re:MongoDB gets support for multi-document ACID transactions by imtringued on Thursday February 15, 2018 @06:17PM (#16388641)
You still need ACID transactions over multiple entries even if your data is nonrelational otherwise there is the potential for item and money duping bugs.

A simple example would be a marketplace.

Player buys item X with Y gold from another player.

1. Server checks that item X exists.

2. Server checks that the player has at least Y gold.

3. Server removes the gold from the player

4. Server gives gold to the seller.

5. Server removes item from marketplace.

6. Server adds item to inventory.

What if someone maliciously crafts two requests in a way that step 2 of the second request happens before step 3 of the first request? The money is deducted properly but the account can now have a negative balance and there are now two instances of the item.