Loading...
0

When should I use MongoDB vs PostgreSQL for a new project?

Starting a new project and trying to pick a database. Everyone seems to either love or hate MongoDB. My app will have users, posts, comments - pretty standard social-app stuff. Is there actually a technical reason to choose one over the other or is it just preference?

1 Answer
0

Best -->

Backend dev with 10+ years of experience here. Both are good databases, but for different reasons.

For your standard social app: PostgreSQL is the better choice.

Here's why:

Your data is relational:

  • Users have posts

  • Posts have comments

  • Comments belong to users

  • Users follow other users
  • This is textbook relational data. PostgreSQL is designed exactly for this.

    Why MongoDB became popular (and when it makes sense):

  • 2010s: NoSQL was trendy

  • Truly schemaless data needs

  • Rapid prototyping (no migrations needed)

  • Data that doesn't fit neatly into tables

  • Extreme horizontal scaling needs
  • Why MongoDB can hurt you:

  • No JOINs = multiple queries or denormalization

  • Data consistency is harder

  • You end up recreating relational features manually

  • Schema changes are actually harder at scale (you can't enforce them)
  • Real talk from experience:

    I've seen so many startups choose MongoDB because it's "modern" and then spend years fighting it:

  • Duplicate data everywhere

  • Complex application-level joins

  • Data inconsistencies

  • Eventually migrating to Postgres anyway
  • When MongoDB actually makes sense:

  • Content management with flexible schemas

  • Logging/analytics data

  • Caching layer

  • Truly document-oriented data

  • Specific gaming/IoT use cases
  • When Postgres makes sense:

  • 95% of web applications

  • Relational data (users, posts, orders, etc.)

  • Complex queries needed

  • ACID compliance matters

  • JSON support still needed (Postgres has JSONB)


My recommendation:

Start with PostgreSQL. It handles JSON when you need flexibility, gives you proper relations for structured data, and won't fight you as you scale.

MongoDB is great for what it's designed for. A social app isn't that.

Your Answer

You need to be logged in to answer.

Login Register
266
Views
1
Answers
0
Votes
Have a Question?

Get answers from the community

Ask Question
Asked By
Justin Garcia
202 reputation
Topic
Databases

Browse more questions in this topic