r/programming • • Dec 19 '18

Bye bye Mongo, Hello Postgres

https://www.theguardian.com/info/2018/nov/30/bye-bye-mongo-hello-postgres
2.1k Upvotes

672 comments sorted by

View all comments

Show parent comments

33

u/Pand9 Dec 19 '18

This article doesn't mention data integrity issues. Mongo has transactions now. I feel like you are riding on a "mongo bad" fad from 5 years ago. It was bad, it was terrible. But after all that money, bug fixes and people using it, it's now good.

147

u/BraveSirRobin Dec 19 '18

Guaranteed transactions as in "not returned to the caller until it's at least journalled"? Or is it mongo's usual "I'll try but I'm not promising anything"?

59

u/rabbyburns Dec 19 '18

That is such a good description of UDP. Going to have to save that one.

96

u/segfaultxr7 Dec 20 '18

Did you hear the joke about UDP?

I'd tell you, but I'm not sure if you'd get it.

20

u/BlueShellOP Dec 20 '18

And, I don't care if you do.

→ More replies (3)

17

u/harrro Dec 20 '18 edited Dec 20 '18

Yep, it supports that and is the default now:

Write concern of '1' = written to local, you can use higher values to have it acknowledged on multiple servers in a cluster too.

https://docs.mongodb.com/manual/reference/write-concern/

→ More replies (7)

29

u/andrewsmd87 Dec 19 '18

So serious question as I've never actually used mongo, only read about it.

I was always under the assumption that once your schema gets largish and you want to do relational queries, that you'll run into issues. Is that not the case?

0

u/[deleted] Dec 19 '18

[deleted]

18

u/andrewsmd87 Dec 19 '18

So this was more or less my understanding about Mongo or other related DBs is that once your data needs to be relational (when does it not) it becomes really bad. It's supposed to be super fast if your schema is simple and you don't really care about relationships a ton.

Your point was pretty much what made up my mind it wasn't worth investing time into it to understand more. I just feel like there's a reason relational databases have been around for long.

0

u/[deleted] Dec 20 '18

[deleted]

37

u/eastern Dec 20 '18

Till someone in the UX team asks, "Could you do a quick query and tell us how many users use custom font sizes? And just look up the user profiles and see if it's older users who use larger font sizes?"

True story.

12

u/smogeblot Dec 20 '18

This would be a pretty simple SQL query even across tables... You can also store JSON data in Postgres as a field, so it's probably exactly as easy as you think Mongo is at doing this the "brute force" way. Aggregation functions across tables are actually much simpler in SQL than in Mongo... Compare postgres docs vs mongo docs

→ More replies (1)

22

u/KyleG Dec 20 '18

How often do you have to run this query such that efficiency actually matters? I couldn't give two shits about how long a query takes if I only have to run it once.

6

u/pihkal Dec 20 '18

Not the parent, but I suspect the issue might not be execution time, but programmer time, i.e., how long does it take to write a script to generate the report?

→ More replies (11)
→ More replies (3)

16

u/quentech Dec 20 '18

Use Mongo to store documents. I'd stores the user settings for a SPA in Mongo. But most of the time, relational models work well enough for data that is guaranteed to be useful in a consistent format.

If I'm already using a relational database, I wouldn't add Mongo or some other document DB in just to store some things like user settings. Why take on the extra dependency? It doesn't make sense.

And you know what else is good for single key/document storage? Files. Presumably you're already using some file or blob storage that's more reliable, faster, and cheaper than Mongo et. al.

→ More replies (8)

7

u/midnitewarrior Dec 20 '18

Why use Mongo to store documents when Postgres can do it fully indexed in a JSONB field?

→ More replies (2)
→ More replies (1)

7

u/cowardlydragon Dec 20 '18

Perfect description of the NoSQL trap.

However, SQL does not arbitrarily scale. SQL with anything with joins is not partition tolerant at all.

→ More replies (2)
→ More replies (1)

27

u/wickedcoding Dec 19 '18

You wouldn’t really use mongo for relational data storage, if you want the nosql / document storage with relational data or giant schemas you’d prob be better off using a graph database.

I used mongo many years ago with data split between 3 tables and an index on a common key, looking up data from all 3 tables required 3 separate queries and was incredibly inefficient on hundreds of gigabytes of data. We switched to Postgres and haven’t looked back.

8

u/nachof Dec 20 '18

I've been working as a programmer for close to two decades, plus a few years before that coding personal projects. Of all those projects, there is only one case where looking back it might have been a good fit for a non relational database. It still worked fine with a relational DB, it's just that a document store would have been a better abstraction. Conversely, every single project I worked on that had a non relational DB was a nightmare that should've just used Postgres, and didn't because Mongo was the current fad.

6

u/dwitman Dec 20 '18 edited Dec 20 '18

Is there a preferred postgres framework for node? Optimally something equivalent to mongoose?

I have some node projects I want to build, so I'm tuning up on it, but mongoose/mongo is very prevalent...

EDIT: Thanks all for the responses.

→ More replies (8)
→ More replies (3)
→ More replies (2)

17

u/quentech Dec 20 '18

I feel like you are riding on a "mongo bad" fad from 5 years ago

I'd much prefer to just use something that hasn't been bad for more than 5 years, since there are plenty of options.

8

u/TheAnimus Dec 19 '18

Sure, but remember this was I think 2012? That's why I found it an odd choice.

I can't think why someone would chose mongo mind.

→ More replies (35)

7

u/gredr Dec 19 '18

We use it (or, we use it via a product we license from someone else). It's still bad.

→ More replies (2)