r/PostgreSQL • • Jan 20 '24

Help Me! Doubt regarding PostgreSQL vs Mongodb

Why very often people say mongodb is not that better and we are being future proof to go with postgres? is there any condition that mongodb can't handle or such. I would love to get an answer that explains why actually why companies are shifting?

49 Upvotes

50 comments sorted by

View all comments

Show parent comment

4

u/kenfar Jan 21 '24 edited Jan 23 '24

Learning to understand how to be effective with a document database doesn't require becoming a parrot for their marketing department. It means understanding strengths, weaknesses, and design patterns:

  • Data Quality: when mongodb replication wasn't atomic and you could overwrite partial records - what do you do?
  • Schemaless: Actually means "millions of schemas" - every row could have different fields with different types. Or you are disciplined, stick to a single schema, and do frequent schema migrations. Which goes against the company's recommendations, goes against their "schemaless" PR, and can take forever on big databases.
  • Joins: are a very powerful adaptability feature. Eventually, most folks discover that they need mongodb to return a document that includes or is filtered by some other piece of data. For example, not only your customer_id at the time of the transaction, but also the customer_name as of today? Simple, just join to your customer table. When joins are cripplingly slow you lose a ton of flexibility.

There are times & places where mongodb may make sense. But like mysql's leadership telling everyone twenty years ago that 90% of all developers don't need transactions, views, subselects, unions, etc - MongoDB spewed a lot of bad advice for people.

EDIT: typos