NoSQL - NoProblem! Mapping your SQL thinking to NoSQL

pdardeau

May 22, 2013

I've been hearing about the virtues of NoSQL for a number of years, but only lately did I really have a good opportunity to dig in and see what all the fuss is about. As with many folks, my background with storage technologies has been 99% standard SQL in common relational databases. The big hurdle for me is how do I go about 'thinking' properly in this brave new world of NoSQL.

To dig in - and for this article - I used a simple music database as my example. I like this example because it's simple enough that everyone understands the concepts, plus I also like music.

This SQL stuff is old hat and most of us could probably do this in our sleep!

How do we go about doing the same thing in this strange new territory of NoSQL?

One bit of advice that was given was "just think of it as a database without the structure". Well, that's exactly the problem that I have -- I don't think of databases without having structure.

So here's how we would think of the problem in a NoSQL situation, like with Apigee's App Services.

We will have a collection for artists, one for albums, and another for songs.

We can roughly think of a collection as being synonymous with a 'table' in relational databases. What's the difference?

NoSQL systems don't have any strict rules on what data you can or can't put somewhere. Huh? Think of it as being similar to SQL, but without the constraints on table structure or referential integrity.

Well, that's kind of the way that SQLite works, isn't it?

Somewhat, but this new territory is even more flexible than SQLite. You see, SQLite doesn't care much about referential integrity and data types, but it still cares a great deal about column names -- meaning you can't decide to add a new piece of data to a table without first issuing the correct ALTER TABLE statement to add the new column.

NoSQL Music Database

Let's take a look at how we go about setting up our music database in App Services.

Wait, I see you did something weird there. You added a 'notes' value for one of the artists, but not for the others. Yep! But notice that we never declared a structure for the artist collection at all. This means that we're free to put whatever we want in it at any time.