Schema is one of those funny words that when you hear it, you kind of get it, but if you’re not familiar with them, then you kind of don’t at the same time. Let me tell you what it is.
A schema is like a blueprint for a building. But it’s for data, not buildings.
How it should be organized, how it relates to other data, its fundamental structure, etc.
Seems like a good idea. And it is. It’s better to have something meaningful than a pile of “data” that you can’t use.
Some schemas are more rigid than others. And while we need some guardrails on managing data, if it’s too rigid, it can create problems.
Such as modifying the schema and therefore the affected data, migrations can get real complex, and sometimes you’ll need to take a system down just to deal with it.
Imagine editing the blueprint of a building mid-construction. It would be a bit like that.
While there are benefits, that’s how a traditional, structured database like SQL can be.
Setting up a schema in an SQL (relational) database requires careful planning—of the tables, columns, data types, keys, etc.
You can’t just stroll up looking like you got dressed in the dark and delete a column. Things will break.
On the other side of things, you have something like MongoDB—a NoSQL database that departs from this level of rigidity. It’s flexible document model unbinds you from a fixed schema and allows a more adaptive approach to data management.
Instead of tables, rows, and columns, MongoDB stores data in a collection of documents and is set apart by its schema-less nature.
Each document is a self-contained unit with its own unique structure. One document could have 5 fields, another 10. It’s arguable that MongoDB represents data more naturally.
As applications and data evolve and without a pre-defined schema, you can add new fields to your documents, remove existing ones, and store nested data structures without major disruptions.
Real World Example
This is crude, but it’ll get the point across.
Let’s say you have a simple blogging platform. You setup fields like title, content, and author.
Then you evolve it by introducing tags, images, and video (so exciting!). With MongoDB, you can just add the new fields to accommodate them without the need for complex migrations or schema redesigns.
The next time the PM or a stakeholder of an app you’re building demands a new feature or the requirements change, you can handle it with some fluidity.
Why Is This Good?
First, you can prototype fast. Developing that new feature, modifying existing ones, or pivoting in a whole new direction doesn’t require wrangling complex schema migrations or dealing with database downtimes.
Let’s face it. Real-world data is messy. The data itself changes. Data types change. Data consistency is still a thing, but it’s a lot easier to tackle when the process is less complex.
And complexity costs. Time, money, and headaches. MongoDB’s approach isn’t merely about storing data differently, it’s a different way of managing it that’s flexible, efficient, and fast.
Schema-Less Data Doesn’t Mean There’s No Structure
It’s a common misconception to equate schema-less with the same level of structure that a former rock band, starving teenage boho artist startup founder might have.
In MongoDB, there are still schemas, but they’re not rigidly enforced at the database level.
Nevertheless, without a fixed schema, data can become inconsistent and messy pretty fast. And while you have the freedom to store documents with varying structures in the same collection, that doesn’t mean you always should.
You still want to have clean data, and that’s going to require some structure. Application-level checks and data validation are crucial for maintaining data integrity and consistency.
In addition to those best practices, leveraging tools that help visualize and manage the data structure can go a LONG way to keep data clean and consistent.
Model Data Without Code Using Form.io
If you didn’t already know, Form.io is built on MongoDB.
I know a guy who’s using Form.io right now to build a proof-of-concept app. He’s not even building forms or embedding forms, which is a pretty significant staple of our platform. I mean, we are named Form.io.
But he is building data resources (which are exactly the same as forms, but classified differently) using the drag and drop form/resource builder and then passing data from the application directly to the resources.
With his limited knowledge of schemas, schema-less data, databases, and whatnot, he’s leveraging Form.io primarily as a database. And the draw for him was that he could “build a database” without knowing anything about backend development.
By defining fields and data types through the structure of a form-resource via drag and drop, the schema and the APIs are defined automatically behind the scenes. And since Form.io handles a significant portion of data validation, the data remains clean and consistent.
Form.io, in essence, bridges the gap between schema-less data flexibility and the need for structure AND enables non-developers power users to model data without backend code.
Form.io gives you the best of both worlds.