Chapter 12: MongoDB
MongoDB is a document-oriented, schema-less database that has been shown to fit in really well with Node.JS applications and cloud deployments.
One of its most interesting features is that unlike MySQL or PostgreSQL, which store data in tables that are generally fixed in their design (schema), MongoDB can store documents of any kind in collections (schema-less).
For example, say you create a table that holds the user profiles of a web application:
When you build your application, you decide your users’ information will be structured around this particular design. You expect to have one or more of the following: first name, last name, email, and Twitter ID.
As applications evolve, business needs change, or as time passes and new needs arise, you might need to add or remove some of those columns.
The fundamental problem, however, with the way most traditional (SQL) databases are optimized to work is that it’s very expensive to make changes to the table design, both operationally and in terms of performance.
Every time you need to make a change to that design, in MySQL, for example, you need to run a command to add a column:
$ mysql
> ALTER TABLE profiles ADD COLUMN . . .
And the same occurs if you remove one or more columns.
With MongoDB, you can think of your data as documents that are flexible in their design. And, as it happens, these documents are stored ...
Get Smashing Node.js: JavaScript Everywhere, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.