Exploration of noSQL: MongoDB

Unless you’ve been living under a rock for the past few years (which apparently is quite comfortable to some starfish), then you’ve probably heard of noSQL. But, if you live by a "if it ain’t broke, don’t fix it" attitude, then you’ve likely stayed close to your more traditional and familiar SQL roots. It’s time to spread those wings and fly, my friends, as we explore the wonderful world of noSQL databases. Like life, noSQL is a journey, so sit back, relax, and enjoy the ride!

MongoDB’s homepage boasts, among a long list of features, agility and scalability. As I discussed over at sqlpronews.com, these are some of the major factors that have brought noSQL databases to the industry. It should be no surprise then that some of the largest sites on the Internet are taking advantage of this increased scalability. Sites like shutterfly, foursquare, bit.ly, The New York Times, and sourceforge are some of the many sites that use mongoDB.

However, what really takes the cake in mongoDB is dynamic schemas. Like traditional SQL databases, mongoDB has databases. Inside these databases are table-like units called collections. Instead of defined columns, however, each document (row) structure can be unique. For example, one document in the collection <code>gameshowhosts</code> could look like:

{
  "name" : "Bob",
  "retired" : true,
  "address" : {
    "street" : "123 Hollywood Blvd.",
    "city" : "Los Angeles",
    "state" : "CA"
  }
}

while another document in the same collection could look like this:

{
  "name" : "Drew",
  "age" : 52,
  "game show" : "Price is Right",
  "address" : {
    "street" : "245 Hollywood Blvd.",
    "city" : "Los Angeles",
    "state" : "CA"
  }
}

Between the two insertions of these documents, no update the schema was necessary. These documents look familiar? That’s because they are JSON, and you can easily work with the database via JSON strings. The use of JSON and the flexible schema make mongoDB a perfect fit when working with web APIs. If the API makes changes to include new fields, no changes to your database schema will be necessary to include this new information.

Have experience working with mongoDB? Post your comments here.

Published
Categorized as Database

By Michael Marr

Michael Marr is a staff writer for WebProNews

Leave a comment