Back to feed
Dev.to
Dev.to
7/3/2026
The Relational Hangover — How I Tried to Force SQL into MongoDB (and Cried in BSON)

The Relational Hangover — How I Tried to Force SQL into MongoDB (and Cried in BSON)

Short summary

Migrating from PostgreSQL to MongoDB requires unlearning SQL design patterns. This post explores three common schema anti-patterns: treating it as relational by creating too many collections, allowing unbounded arrays that exceed BSON limits, and overusing $lookup joins. Solutions include embracing denormalization, splitting arrays into separate collections with references, and designing schemas around actual query patterns.

  • Avoid creating too many collections—embed related data to leverage MongoDB's document model
  • Never allow unbounded arrays within documents—split into separate collections using references or the Subset Pattern
  • Minimize $lookup operations in high-frequency queries—denormalize strategically for sub-100ms latency

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more