Database Reference
In-Depth Information
MongoDB is a database management system designed for web applications and
internet infrastructure. The data model and persistence strategies are built for high
read and write throughput and the ability to scale easily with automatic failover.
Whether an application requires just one database node or dozens of them,
MongoDB can provide surprisingly good performance. If you've experienced difficul-
ties scaling relational databases, this may be great news. But not everyone needs to
operate at scale. Maybe all you've ever needed is a single database server. Why then
would you use MongoDB?
It turns out that MongoDB is immediately attractive, not because of its scaling strat-
egy, but rather because of its intuitive data model. Given that a document-based data
model can represent rich, hierarchical data structures, it's often possible to do with-
out the complicated multi-table joins imposed by relational databases. For example,
suppose you're modeling products for an e-commerce site. With a fully normalized
relational data model, the information for any one product might be divided among
dozens of tables. If you want to get a product representation from the database shell,
we'll need to write a complicated SQL query full of joins. As a consequence, most
developers will need to rely on a secondary piece of software to assemble the data into
something meaningful.
With a document model, by contrast, most of a product's information can be rep-
resented within a single document. When you open the MongoDB JavaScript shell,
you can easily get a comprehensible representation of your product with all its infor-
mation hierarchically organized in a JSON -like structure. 1 You can also query for it and
manipulate it. MongoDB's query capabilities are designed specifically for manipulat-
ing structured documents, so users switching from relational databases experience a
similar level of query power. In addition, most developers now work with object-
oriented languages, and they want a data store that better maps to objects. With
MongoDB, the object defined in the programming language can be persisted “as is,”
removing some of the complexity of object mappers.
If the distinction between a tabular and object representation of data is new to
you, then you probably have a lot of questions. Rest assured that by the end of this
chapter I'll have provided a thorough overview of MongoDB's features and design
goals, making it increasingly clear why developers from companies like Geek.net
(SourceForge.net) and The New York Times have adopted MongoDB for their proj-
ects. We'll see the history of MongoDB and lead into a tour of the database's main
features. Next, we'll explore some alternative database solutions and the so-called
NoSQL movement, 2 explaining how MongoDB fits in. Finally, I'll describe in general
where MongoDB works best and where an alternative data store might be preferable.
1
JSON is an acronym for JavaScript Object Notation . As we'll see shortly, JSON structures are comprised of keys
and values, and they can nest arbitrarily deep. They're analogous to the dictionaries and hash maps of other
programming languages.
2
The umbrella term NoSQL was coined in 2009 to lump together the many nonrelational databases gaining in
popularity at the time.
Search WWH ::




Custom Search