MongoDB & Mongoose: Lifeblood and Backbone

Zachary Hester
3 min readMar 15, 2021

The sun is going up and down over a frantic New York City. Developers are click-clacking on their blocky computers and this great voice in the sky is telling me that software is disrupting every industry. I’m eating pizza and hungover and just graduating college. It’s 2010. There’s a couch and a coffee table and a big CRT television with this loud commercial on.

He says databases are the lifeblood and backbone of the internet. Databases are old, he says. They’re outdated and built on tech from forty years ago. I’m not old, not yet. Why are my parent’s databases still the backbone of the internet? But don’t worry, the voice says. There’s now a modern alternative. MongoDB: a database designed for today and tomorrow’s applications.

So, what is MongoDB, exactly?

Well, a database program, for starters. What may be more interesting though, is what it is not. MongoDB, unlike most of its predecessors, is a NoSQL database. This means it stores and retrieves data in ways other than the tabular relations we see in relational databases. It may help to think of it this way: SQL databases are not unlike excel spreadsheets. Rows and rows and rows of columns of data. This can lead to chunky, slow, and unwieldy data retrieval. Conversely, MongoDB operates as a document-oriented database.

The document-oriented database is a subclass of the key-value store databases. It helps to picture the basic JavaScript object. It also may be a clue as to why and how MongoDB is able to offer a quick and scalable solution to many of the issues our developers face today when building an app.

Unlike relational databases (RDB), where a programmer may be forced to pull from data spread across multiple tables, document-oriented databases store all the necessary information in one document across many various and different objects.

You can imagine how this is a boon in efficiency. Each object can have their own unique set of key-value pairs. All the information does not have to be constructed together in one large, massive table where there may be little correlation between some rows and columns. Ultimately, the goal of NoSQL databases (and by extension, MongoDB), is to store data the way the developer considers best, so that the databases doesn’t impose any unnecessary limitations.

Enter the Mongoose.

A framework for the database giant, Mongoose allows for elegant mongoDB object modeling. They make it clear from the first line on their website that they solve for the drag that is MongoDB validation, casting and logic boiler-plating.

Mongoose is an ODM (object document mapper). This allows your NodeJS app to speak directly with your MongoDB database. In short, this makes everything simpler and more JavaScript friendly.

Mongoose creates an easy-to-use object reference when interacting with MongoDB. The database actually gets modeled within our code. In application, I actually found it helpful to think of Mongoose like a constructor function.

Mongoose is built around schema. Mongoose’s schema will actually map to the pertinent MongoDB collection and defines the shape of that document from MongoDB. All this means that, from the developer’s end, we’re able to render data from our database in JS object form. It may be helpful to read about their permitted SchemaTypes here.

Databases are the backbone of the internet. If this is the information highway, it stands for good reason that we need — not only multiple databases types (NoSQL/ SQL) — but also smart, intelligent packages that allow us to easily render, store, and retrieve that information. Mongoose helps solve for that.

--

--