Where database blog posts get flame-broiled to perfection
Alright, settle down, kids, let ol' Rick pour himself some lukewarm coffee from the pot that's been on since dawn and read what the geniuses have cooked up this time. "Relational database joins are, conceptually, a cartesian product..." Oh, honey. You just discovered the absolute, first-day-of-class, rock-bottom basics of set theory and you're presenting it like you've cracked the enigma code with a JavaScript framework.
Back in my day, we learned this stuff on a green screen, and if you got it wrong, you didn't just get a slow query, you brought a multi-million dollar IBM mainframe to its knees and had a guy in a suit named Mr. Henderson asking why the payroll batch job hadn't finished. You learned fast.
So you've "discovered" that you can simulate a CROSS JOIN. And to do this, you've built this... this beautiful, multi-stage Rube Goldberg machine of an aggregation pipeline. $lookup, $unwind, $sort, $project. It's got more steps than the recovery procedure for a corrupted tape reel. You know what we called this in 1985 on DB2?
SELECT f.code || '-' || s.code FROM fits f, sizes s;
There. Done. I wrote it on a napkin while waiting for my punch cards to finish compiling. You wrote a whole dissertation on it. Itâs adorable, really. You spent four stages of aggregation to do what a declarative language has been doing for fifty years. But you get to use a dollar sign in front of everything, so I guess it feels like you're innovating.
And then we get to the real meat of the genius here. The "better model": embedding. Youâve just performed this heroic query to generate all the combinations, only to turn around and stuff them all back into one of the tables. Youâve rediscovered denormalization! Congratulations! We used to do that, too. We called it "a necessary evil when the I/O on the disk controller is about to melt" and we spent the next six months writing complex COBOL batch jobs to keep the duplicated data from turning into a toxic waste dump of inconsistency.
But you, youâve branded it as a feature. "Duplication has the advantage of returning all required information in a single read." Yes, it does. It also has the advantage of turning a simple update into a nightmare safari through nested arrays.
updateMany for that with a fancy arrayFilters. Thatâs cute. Youâve just implemented a WHERE clause with extra steps and brackets.fit.code and change it everywhere.Youâre creating data integrity problems and then patting yourself on the back for inventing clever, document-specific ways to clean up your own mess. We had a solution for this. It was called normalization. It was boring. It was rigid. And it worked.
But this part... this is the chef's kiss right here:
Unlike relational databasesâwhere data can be modified through adâhoc SQL and business rules must therefore be enforced at the database levelâMongoDB applications are typically domainâdriven, with clear ownership of data and a single responsibility for performing updates.
Bless your heart. You're saying that because youâve made it impossible for anyone to run a simple UPDATE statement, your data is now safer? You haven't created a fortress of data integrity; youâve created a walled garden of blissful ignorance. You've abdicated the single most important responsibility of a databaseâto guarantee the integrity of the data it holdsâand passed the buck to the "application's service."
Iâve seen what happens when the "application's service" is responsible for consistency. Iâve seen it in production, at 3 a.m., with a terabyte of corrupted data. I've spent a weekend sleeping on a cot in a data center, babysitting a tape-to-tape restore because some hotshot programmer thought he was too good for a foreign key constraint. Your "domain-driven" approach is just a fancy way of saying, "we trust that Todd, the new front-end intern, will never, ever write a bug." Good luck with that.
And then you have the audacity to wrap it all up by explaining what a one-to-many relationship and a foreign key is, as if you're bequeathing ancient, forgotten knowledge to the masses. These aren't "concepts" that MongoDB "exposes as modeling choices." They are fundamental principles of data management that you are choosing to ignore. Itâs like saying a car "exposes the concept of wheels as a mobility choice." No, son, you need the wheels.
So go on, build your systems where every service owns its little blob of duplicated JSON. Itâs a bold strategy. Let's see how it works out when your business rules "evolve" a little more than you planned for.
Now if you'll excuse me, I've got a JCL script that's been running flawlessly since 1988. It probably needs a stern talking-to for being so reliable. Keep up the good work, kid. You're making my pension plan look smarter every day.