Cover by Guillermo Rauch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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:

9781119963103-untb1201.png

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required