The title is a bit provocative, I agree!
I just read an article by Sarah Mei (which is a little dated but still seems current) that opened my eyes to a problem I had been seeing since I started development.
http://www.sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/
NoSQL is, I think, a bad idea in 95% of cases.
When I started learning webdev a little more than two years ago, it was hard to miss the "trendy" things, React, MongoDB, serverless, and so on.
Hard to make a choice when a lot of discussions turned out to be more clan wars (Mac/PC, Nvidia/AMD...) than real arguments.
And I think that NoSQL database is part of these unthinking choices for many new developers.
I've worked on 3 projects in the last year and a half, and each time, I chose Firestore or MongoDB for my database.
And each time, I found myself in the middle of the project duplicating data, trying to force links between documents and the result was far from ideal.
Today, I decided to learn SQL and to stop using NoSQL databases except in very specific cases.
Did you have this kind of epiphany? Do you think that NoSQL databases can fit any situation?
I have been working on a large project (10+ devs) running MongoDB in production for the last 2.5 years.
I agree with this post, for a few reasons:
I agree that Mongo can be fast for application prototyping, but it’s then hard to get off it once you’ve got a prototype. I don’t really think prototyping in SQL is that much slower if you use a high-productivity framework like Rails or Laravel.
There are definitely some valid use cases for Mongo, I just don’t think the majority of business applications where Mongo is the primary storage tier is one of them.
Just remember, you can’t spell Mongo with “OMG NO”. ;P
Very similar experience! MongoDB is great, but choosing for its simplicity is the wrong reason. You will still have to deal with:
One thing I would highly recommend: Don't use Mongoose. It's basically trying to make MongoDB relational and that's exactly what is going to give you trouble in the longer run.
Also agree about mongoose. Populate is super dangerous because it hides the complexities of relational data. It’s schema enforcement also has so many holes for updates.
Mongoose came about in a time before Mongo natively supported schemas (pre 3.6). Really, I would probably put a light wrapper around the core driver and use the built in JSON schema-like stuff for validating documents: https://docs.mongodb.com/manual/core/schema-validation/
True, that might be the best way to go. I feel our native driver projects are also easier to test and are less error-prone compared to Mongoose.
PostgreSQL supports the JSONB datatype which can allow for some document db like use cases to exist alongside a proper relational schema.
I have been exploring Postgres lately and there is a ton you can do if you learn SQL.
It's really is not that black & white. We've also failed with MongoDB at SoundCloud
https://developers.soundcloud.com/blog/web-scale-statistics-failing-with-mongodb
That still doesn't mean I would completely rule it out for all use cases. It all depends.
How much data do you have? How fix is your schema? What read/write loads do you expect? What are the access patterns? Will you use it in a cluster setup? There are many angles to this.
What I also like to note: Not all NoSQL databases are the same. They are often very niche products - and in that niche, can do a pretty darn great job. But your data and even more so, your data modeling skills must align. Coming into this with a SQL mindset might well end up in some tears.
SQL databases are old, trusty work horses that do a fine job for 80% of the problems. After all these years we have somewhat decent tools and more importantly experience with them. But also be aware of that bias. In fact - if you take a step back, isn't it really a bit awkward we are still pressing object graphs into tables? We just have gotten very good and accustomed to it.
Just use what you feel comfortable with and what does the job for now. Just watch the dataset in comparison to your indices and memory usage. When you need to scale it's a good problem to have. Often enough that doesn't just impact your database but your architecture as a whole.
Feel free to reach out when you get into trouble or have more specific questions.
https://twitter.com/tcurdt
Agree with this. It depends.
I think Mongo positions itself as a non-niche NoSQL DB that can do anything for any app. That makes sense because they have monstrous VC funds to return on.
the node community seems to treat it as A general purpose DB as well. We need more thoughts about what it depends on so folks can choose Mongo thoughtfully.
I think it's exactly the problem. Mongo could be great, but the problem I see right now is this "new shiny object" syndrom we talked about. People don't think about their database and the structure beforehand.
And I agree with all the answer from indie hackers here because it's mostly "that depends, but be careful what you choose". The problem is, from what I see on tutorials / twitter etc, there is not enough warning about the fact that choosing the right database for your project is crucial.
Great timing, yesterday I made the jump on an internal work project from PHP/MySQL to Electron/React/MongoDB. The common "stick with what you know" was shadowed by "cool new stuff".
I used to be guilty on making decisions under the influence of the shiny object syndrome. I tried to build some projects using nosql instead of sql. It's way easier and faster to start development and get it running, but once you start adding more and more, you end up fighting the limitations of such database.
It all boils down to the requirements, and in 99% of the cases, the core functionality of a web application is relational data (if you have users, no matter what the other data models/resources are, you end up with at least the ownership relationship between users/teams/companies and those resources.
Nowadays, as NoSQL, I use mostly redis for caching and a search engine (elasticsearch or solr) for indexing big quantities of data that need searching. I have MongoDB too many chances and each time, I was ending up fighting it more than it helping me.
Yeah, I actually find it advantageous to prototype using MongoDB, especially if you can expect your schemas to change rapidly. Less overhead early on, but maybe not the greatest choice long term.
Mongodb and other similar db designs have its role. If you know what the data will be beforehand, an SQL structured scheme isn’t so bad.
The biggest problem with MongoDB is that it's most often used as an RDS anyway. So why are they just not using an RDS? MongoDB has serious drawbacks when you try to use it in this way. Just use Posters, it has the best of both worlds.
The problem I think is that Mongo is sold in a lot of cases as a rapid prototyping tool, and something where you can store data and not "really" care about how you're saving that. That makes it very attractive to a lot of newer or more front-end focused devs, but really presents a lot of issues when you move passed a prototyping stage.
I recall the first time I used Mongo it was nice not really having to worry about schema and just saving my data. As you can imagine, this ended up causing problems down the line and the speed I saved upfront I probably lost trying to fix my data.
That said, Mongo isn't a bad choice but I always say to keep in mind that
Most data is inherently relational. Think long and hard before you use Mongo (or any NoSql database for that matter) and think through why it seems beneficial.
Understand that your schema shouldn't be a free for all. Especially as a project grows, having some sort of schema enforcement or validation is going to be crucial. If you're just randomly saving documents with differing fields and not really thinking through the repercussions of that you're going to have a bad time.
I agree... I used to be in the same boat...now I use Nextjs+firebase for almost all my side hustles
This is a great discussion! I've used both SQL and NoSQL as a developer, and have wondered about the "hype vs functionality" paradigm many times. This discussion has made it clear that my concerns were valid.
It's always interesting to me that new devs reach for NoSQL first. I've always found SQL + relational DBs (preferably PostgreSQL) to be much easier to work with, and to reason about. The "hard part" is figuring out the schema, but that's the same with NoSQL, but now I don't end up with runtime errors as often.
It depends on the use case/context. Pretty informative article though.
It depends what you need. Doing a non relational database and simulating relational DB is always a bad idea.
things are made different with a purpose, and if we are using new things with an old, existing approaches, it will always result in some form of Frankenstein.
I mostly agree with you. But also I think you can mitigate a lot of these problems by using a ODM like Mongoose.
I feel like NoSQL is good for prototyping and a more lean approach to get out an MVP, because in most cases you don't how the data will look like. Long term though, it's not as reliable as SQL.
i have bought a project with a previous owner had it on mongodb , performance was very bad and it impacted the project so hard that he saw no way out anymore. first thing i did was migrate it to mysql.
but in another instance i bought a project that was on mysql , and the performance was bad too ... it was a 10 minute fix : adding indexes to the tables ...
whatever you select to store your data , take the time to find the best solution and invest time in reading some articles how to get good performance out of your stack
With any new tech, my instinct is to take a look and maybe play around with it, but wait a couple years before using it for anything serious - enough time for the hype to wear off, the success/failure stories from early adopters to come out, the ecosystem to grow and the bugs to be fixed. In the case of MongoDB that would probably have been a wise decision. It's still around, but there is more clarity about where it shines and where you'd be better off with an RDBMS.
Having or not having the schema has it's own pros and cons. As you mentioned, the biggest advantage of schema is consistency of your data.
But in some cases, when you work with unstructured data (from third-party services, for example) or for rapid development not having the schema could be advantage.
This comment was deleted 4 years ago.
This comment was deleted 3 years ago.