🔥 The DB Grill 🔥

Where database blog posts get flame-broiled to perfection

Many-to-One: Stronger Relationship Design with MongoDB
Originally from dev.to/feed/franckpachot
December 15, 2025 • Roasted by Jamie "Vendetta" Mitchell Read Original Article

Oh, this is just delightful. What a wonderful trip down memory lane. Reading this reminds me of the good old days in the pod—the smell of lukewarm coffee, the hum of over-provisioned servers, and the quiet desperation of a product manager trying to explain the roadmap. You've really captured the essence of it all.

It starts off so beautifully, with that classic, almost quaint, setup: a relational database is simple and predictable, but oh no, it might surprise developers! The horror! Thank goodness we have a flexible document model to protect them from the sheer terror of... data integrity.

I must applaud the masterful demonstration of first denormalizing the data. The aggregate pipeline with a giant $switch statement is a true work of art. It’s a beautiful, handcrafted solution that elegantly solves the problem of having a separate, clean departments table. Why have two small, fast tables when you can have one two-million-document collection where you update every single employee record just to add a department description? It’s the kind of forward-thinking that keeps the lights on in the cloud billing department. It’s not tech debt, it’s a “rich document model.”

And the initial query performance... 1.3 seconds! A stunning result. It's a bold move to show a full collection scan as your starting point. It really builds the dramatic tension. Then, like a magician revealing the dove up his sleeve, you add an index and—poof!—the query is instantaneous. Groundbreaking. I remember when we first discovered that indexes make queries faster. It was a wild Tuesday. We almost filed a patent.

But my favorite part, the part that truly resonates with the scarred tissue of my soul, is the journey with $lookup.

executionTimeMillisEstimate: Long('94596')

Ah, yes. The 94-second aggregation. Chef’s kiss. That’s the $lookup I remember. The one that looked so great on a slide deck and single-handedly funded the SRE team's therapy bills. You can almost feel the emergency all-hands meeting in that number. You’ve perfectly captured that magical moment where developer-friendly syntax meets the cold, hard reality of physics. The "query planner pushing down the filter" is a nice touch, too. It’s like a little hero, deep in the bowels of the engine, frantically trying to prevent the whole thing from catching fire. We used to call that feature "Project Hope."

Then, the article guides us to salvation with a solution of breathtaking ingenuity:

It’s just… wow. To think, after all this modeling flexibility, we've innovated our way back to exactly how you’d do it with a relational database in 1995, just with more steps and manual caching. It’s beautiful. The circle of life.

And just when I thought the performance art was over, you embedded an array with 1.4 million ObjectIds into a single document. A 12MB document. This is truly inspired. It’s like strapping a jet engine to a unicycle to win a drag race. Sure, it’s technically possible, and it makes for a hell of a demo, but you’re praying the whole time that the frame doesn't vaporize. Showcasing that it can be done, while gently whispering “this is generally not advisable,” is the kind of corporate messaging that I have come to know and love. It's a monument to the possible, and a warning to the wise.

Finally, we arrive at the "Computed Pattern," where we pre-aggregate just the top employees into an array. A brilliant solution, as long as you don't mind building your own incremental materialized view system with application-level triggers. The balance here isn't between embedding and referencing; it's between a working application and the on-call engineer's sanity.

The closing thoughts are the perfect cherry on top:

MongoDB, by contrast, encourages stronger schema design for relationships once your access patterns and cardinality are well understood.

That’s a lovely way of saying, “We give you all the rope you could ever want, and if you hang yourself, it’s because you lacked vision.” It's not a bug-ridden minefield of performance foot-guns; it’s an encouragement to be a better architect. The sheer audacity is magnificent.

Thank you for this masterpiece of technical fiction. It was a nostalgic and deeply cathartic read. I shall now go unsubscribe from this blog forever, my heart full and my vendetta validated. Cheers.