MongoDB Core Concepts Part 2

Ok, so now that we’ve covered the fact that relational technologies were (in large part) created with a primary goal of maximizing efficiency of disk space by leveraging a system of references – multiple tables to store data only once and refer to it multiple times, let’s take a look at another system of storage that provides a different set of efficiencies.

JSON Document Structure

MongoDB is NOT a JSON database… I like to say that right out of the gate.  Sometimes people will inaccurately report that MongoDB is a JSON database or that it stores data in JSON.  It does not.  It does, however, support JSON fully.

MongoDB stores data in BSON.  There’s a full specification over at BSONspec.org if you’re interested in the gory details.  What’s the difference, you might be asking?  Hang on… we’ll get there.

Let’s start with a view of the difference between how we store data in the relational world, vs. how we store data in JSON/BSON.

First, a bit of terminology to make sure we’re all on the same verbal page.

RDBMSMongoDB
TableCollection
RowDocument
ColumnField
Secondary IndexSecondary Index
JoinsEmbedded documents, linking, $lookup & $graphLookup
GROUP_BYAggregation Pipeline

Now, if you’re like me and have developed applications designed to run with a relational database backend, you’ll naturally begin to think about the data elements you’ll manage in your applications and break them into distinct types… maybe even calling them tables… defining the columns for each different piece of data you’ll store and manage.  Further, you’re likely to start thinking about multiple tables for very different pieces of information or data.  For example, People and Cars.  If we’re developing an application that will manage people and the cars they own, you’ll likely end up with something that looks like the following:

Now this is quite logical, especially in light of the fact that you’ve likely been devising these relational schemas for quite some time.

Now to create this structure, we need to develop some DDL, or Data Definition Language.  This, in relational parlance is how we create a schema.  In a RDBMS, the schema lives separately from the data.

View SQL Schema

This is part of the problem associated with relational technologies.  All of that definition language above is not needed if we don’t have a schema… if we don’t care about establishing constraints and column definitions ahead of time.

Instead, we can immediately concentrate on creating documents right in our code.  Let’s look at a simple example using NodeJS.

This simple example will insert one document into a collection called peoplecars in a database also called peoplecars.

The document looks like this:

This simple example was written in NodeJS, but know that there are drivers for literally every modern language.  Here are links to just a few:

I hope you found this introduction useful.  If you have questions or want to learn more, reach out!  Use the comment box or contact me on Twitter.

 

 

 

MongoDB Core Concepts

Maybe you’re a technical professional who’s done work with only relational databases… Oracle, SQL Server, MySQL, etc.  Maybe you’ve just heard of NoSQL databases but haven’t had the chance to dive in and understand what, exactly these modern data storage mechanisms are all about.

The purpose of this article is to provide a high level understanding of exactly what MongoDB is, and why solutions like MongoDB exist.

To understand why MongoDB exists, we need to go back in time to the 1970’s and 1980’s when Relational Technology was developed.

SQL was initially developed at IBM by Donald D. Chamberlin and Raymond F. Boyce in the early 1970s. This version, initially called SEQUEL (Structured English Query Language), was designed to manipulate and retrieve data stored in IBM’s original quasi-relational database management system, System R, which a group at IBM San Jose Research Laboratory had developed during the 1970s. The acronym SEQUEL was later changed to SQL because “SEQUEL” was a trademark of the UK-based Hawker Siddeley aircraft company.

In the late 1970s, Relational Software, Inc. (now Oracle Corporation) saw the potential of the concepts described by Codd, Chamberlin, and Boyce, and developed their own SQL-based RDBMS with aspirations of selling it to the U.S. Navy, Central Intelligence Agency, and other U.S. government agencies. In June 1979, Relational Software, Inc. introduced the first commercially available implementation of SQL, Oracle V2 (Version2) for VAX computers.

After testing SQL at customer test sites to determine the usefulness and practicality of the system, IBM began developing commercial products based on their System R prototype including System/38, SQL/DS, and DB2, which were commercially available in 1979, 1981, and 1983, respectively.

If you think about the 1970’s from a financial perspective – how much did the elements of an application cost?  Well, there’s the computer – disk, cpu, and memory.  Each of these elements were much more expensive back then.

In fact, let’s look at the cost of hard disk specifically.

Price of a Gigabyte by Year
1981

$300,000

1987

$50,000

1990

$10,000

1994

$1000

1997

$100

2000

$10

2004

$1

2010

$0.10

And then there’s the developer or database administrator – the amount of money paid to these individuals to design, develop or maintain the database.  This variable of the equation was much cheaper than today.  Let’s dig into this a bit.  To understand how differently we (computer programmers, developers, and DBA’s) are compensated between the 80’s and today, let’s look at two key factors – the rate of pay (then, and now) as well as the the U.S. Rate of Inflation.  First – finding the rate of pay for a computer programmer from the 1980’s proved difficult – but I did find one source which listed the average weekly earnings for a computer programmer at $472 per week.  Which works out to roughly $24k per year.

Source: https://www.bls.gov/opub/mlr/1985/01/rpt1full.pdf

Now, if we calculate the impact of inflation on this number, we get to roughly $71k per year.

Source: http://www.in2013dollars.com/1980-dollars-in-2017?amount=24000

This may not be the most scientific method – but let’s assume I’m within a few thousand dollars.

Even if we’re at the 25th Percentile ($60k) today, we’re still earning more than 27% more for doing the same work.  That’s a sizable increase.  At the high end, we’re earning more than 82% more for the same jobs.

So, why go into this detail?

We, as DBA’s and developers are earning more than ever before and the costs that are incurred as part of having us working on applications represent a larger slice of the overall cost pie.  Therefore, it only makes sense that we should be leveraging systems that maximize the efficiency to our resource… to us, rather than to the infrastructure.

It just doesn’t make sense to use a system that’s focused on reducing the number of bits and bytes stored at the cost of developer and DBA time.

Continue Reading

Paris Trip Notes – Day 5

Sun 10-1Mon 10-2Tue 10-3Wed 10-4Thu 10-5Fri 10-6

Today is Friday October 6th, 2017.  I’ll fly back home to Philadelphia today.  Once again the previous day kept me busy with work, and preparation, and helping colleagues in the office so little time for tourism.

I did however, enjoy a phenomenal meal at Monsieur Bleu last night.  Another incredible experience.  Prior to coming to Paris, I was on a limited carbohydrate diet – a ketogenic diet.  I made a conscious decision to relax that and last night was a massive departure… I loved it.  I ate (and thoroughly enjoyed) the pre-meal bread with amazing salted butter.  I ordered a beef dish – and devoured it.  I even enjoyed a blissful dessert called Café gourmand.  Essentially this was a plate of a variety of small(ish) pastries and mini-cakes and an espresso.  I later learned that in french gourmand translates to the english word greedy.   That sums it up really well – I want to taste ALL of these amazing desserts.

This has been an incredible, albeit short peek into a culture to which I’ve had thus far had little visibility.  I’m grateful to have experienced it and I hope to return very soon.

Word(s) of the day:

FrenchEnglishAudio
 Je suis reconnaissant I am thankful

Franco-Fact:

The French invented the metric system, the decimalized way of counting and weighing, in 1793 – the original prototype kilo, Le Grand K, is a cylinder made in the 1880s out of platinum and iridium and about the size of a plum, and was the only object known to scientists to have a mass of exactly 1kg.  Everything else measured in kilograms is defined by Le Grand K.  It’s kept locked away under three vacuum-sealed bell jars in a vault in the International Bureau of Weights and Measures (BIPM) in Sevres, France.  Duplicate cylinders were sent around the world and every so often they’re compared to the original.  But Le Grand K mysteriously seems to be losing weight: The last time it was weighed, in 1988, it was found to be 0.05 milligrams (less than a grain of sugar) lighter than the copies.

Photo(s) of the Day

 

Paris Trip Notes – Day 4

Sun 10-1Mon 10-2Tue 10-3Wed 10-4Thu 10-5Fri 10-6

Today is Thursday October 5th, 2017.

Last night brought an opportunity to catch-up with a colleague who manages a region of Solutions Architects at MongoDB at an amazing restaurant – Livio, à Neuilly-sur-Seine.

livio à neuilly

Livio gained unfortunate attention after the tragic terror attack in November 2015, when the owner/proprietor Stephane Albertini, and the head Chef Pierre Innocenti lost their lives.

The food was incredible and the conversation even better… great time.

A last minute deliverable for a very important client meeting has cut the available time for this update short… hope to create a more interesting update for tomorrow, my last day in Paris.

Word(s) of the day:

FrenchEnglishAudio
 Pourriez-vous parler plus lentement, s’il vous plaît?Could you speak more slowly, please? Coming soon
d’accordAgree.  I kept hearing this sprinkled throughout conversation.  Dukor… Dahkor… I asked a colleague and he said he couldn’t recall saying any words that sounded like that.  I finally heard it on the news and read the closed caption… “d’accord”.Coming soon

Franco-Fact:

In France, the elevators are base-zero.

Zero is Ground

Photo(s) of the Day: