DEV Community

Carin Chapman
Carin Chapman

Posted on

MongoDB: Not your grandaddy's DBMS

MongoDB is a flexible, noSQL database management system that allows for changes with an alacrity that modern technology and web-frenzy demands. If an app needs to regularly keep up with a constantly fluctuating stream of data, more traditional, SQL DBMS sometimes won't cut it.
Don't get me wrong; SQL has a place and time. If, say, an organization has a predictable set of data it needs to track and a predictable way it need to track said data, a SQL DBMS is the ticket. With a SQL DBMS, tables are created in advance and are pretty rigid. You can't just pop into the DB and decide you're going to populate a new column in a jiff. You can do that...you'll just hate it and it won't happen in a jiff. Of if you need to fetch any data, you'll have to maneuver through what can sometimes be an esoteric minefield of "right joins" and obtuse selectors that lead you down a labyrinthine path of hell. Of course--as with anything new--if you stick with it, writing raw SQL queries get easier and easier over time.
On the other hand, MongoDB and other noSQL DBMS offer easily manipulated data and the language for fetching data feels way more simple because its query language is good old fashioned JavaScript. It also stores all your data in JSON-like objects, and who doesn't love the comfort of a recognizable and familiar object? Every time I use MongoDB, it's like the scene in Ratatouille when the food critic takes a bite and has a flash back to his childhood: all those objects and all that JavaScript brings me back to the first days of learning to code and gets me all misty eyed. Plus, comfortable developers = better code.
On top of all that, MongoDB does so much stuff for you. For instance, it automatically adds unique an _id field to all entries in documents. Do you need to add it yourself? No! Do you need to set primary keys and foreign keys and blah-blah-blah? No! Do you need to mess with messy rules like adding "auto-increment"? No! Using it is a simple, straightforward process that will feel natural. It even automatically creates a collection for you, after you use a model to create a document once, without you having to do the work yourself. (Although you can still choose to create the collection manually if you want.)
If you tack on the use of Mongoose, you've got a really straightforward and powerful tool for crafting, saving, querying, manipulating, and using your data.
All that said, it probably won't ever replace the use of a SQL database. A lot of bigger companies in fact use both an SQL and a noSQL database to manage their data. Some data after all will be stagnant and need to be organized in reliable ways that are set-in-stone and intentionally do not fluctuate. Other kinds of data will be loosey-goosey and need the flexibility of noSQL. Ultimately, it's good to be comfy with both and to know why and when to use one over the other.

Oldest comments (0)