Database Reference
In-Depth Information
Lacking Innate Support for Transactions
Here's another important design decision by MongoDB developers: The database does not include transactional
semantics (the element that offers guarantees about data consistency and storage). This is a solid tradeoff based on
MongoDB's goal of being simple, fast, and scalable. Once you leave those heavyweight features at the door, it becomes
much easier to scale horizontally.
Normally with a traditional RDBMS, you improve performance by buying a bigger, more powerful machine. This
is scaling vertically, but you can only take it so far. With horizontal scaling, rather than having one big machine, you
have lots of less powerful small machines. Historically, clusters of servers like this were excellent for load-balancing
websites, but databases had always been a problem because of internal design limitations.
You might think this missing support constitutes a deal-breaker; however, many people forget that one of the
most popular table types in MySQL ( MYISAM —which also happens to be the default) doesn't support transactions,
either. This fact hasn't stopped MySQL from becoming and remaining the dominant open source database for well
over a decade. As with most choices when developing solutions, using MongoDB is going to be a matter of personal
preference and whether the tradeoffs fit your project.
MongodB offers durability when used in tandem with at least two servers, which is the recommended
minimum for production deployments. It is possible to make the master server wait for the replica to confirm receipt
of the data before the master server itself confirms that the data has been accepted.
Note
Although single-server durability is not guaranteed, this may change in the future and is currently an area of
active interest.
JSON and MongoDB
JSON (Java Script Object Notation) is more than a great way to exchange data; it's also a nice way to store data. An
RDBMS is highly structured, with multiple files (tables) that store the individual pieces. MongoDB, on the other hand,
stores everything together in a single document. MongoDB is like JSON in this way, and this model provides a rich and
expressive way of storing data. Moreover, JSON effectively describes all the content in a given document, so there is no
need to specify the structure of the document in advance. JSON is effectively schemaless (that is, it doesn't require a
schema), because documents can be updated individually or changed independently of any other documents. As an
added bonus, JSON also provides excellent performance by keeping all of the related data in one place.
MongoDB doesn't actually use JSON to store the data; rather, it uses an open data format developed by the
MongoDB team called BSON (pronounced Bee-Son), which is short for binary JSON. For the most part, using BSON
instead of JSON won't change how you work with your data. BSON makes MongoDB even faster by making it much
easier for a computer to process and search documents. BSON also adds a couple of features that aren't available
in standard JSON, including the ability to add types for handling binary data. We'll look at BSON in more depth in
“Using Document-Oriented Storage (BSON),” later in this chapter.
The original specification for JSON can be found in RFC 4627, and it was written by Douglas Crockford. JSON
allows complex data structures to be represented in a simple, human-readable text format that is generally considered
to be much easier to read and understand than XML. Like XML, JSON was envisaged as a way to exchange data
between a web client (such as a browser) and web applications. When combined with the rich way that it can describe
objects, its simplicity has made it the exchange format of choice for the majority of developers.
You might wonder what is meant here by complex data structures . Historically, data was exchanged using the
comma-separated values (CSV) format (indeed, this approach remains very common today). CSV is a simple text
format that separates rows with a new line and fields with a comma. For example, a CSV file might look like this:
Membrey, Peter, +852 1234 5678
Thielen, Wouter, +81 1234 5678
 
 
Search WWH ::




Custom Search