EDWARD'S LECTURE NOTES:
More notes at http://tanguay.info/learntracker
C O U R S E 
MongoDB for Node.js Developers
Andrew Erlichson, MongoDB University
https://university.mongodb.com/courses/10gen/M101JS/2014_June/about
C O U R S E   L E C T U R E 
MongoDB Introduction
Notes taken on June 4, 2014 by Edward Tanguay
•
what is MongoDB
•
non-relational
•
doesn't store in tables
•
stores in JSON documents
•
key/value
•
can also be key/array
•
and key/array(key/...)
•
MongoDB is a JSON document store
•
MongoDB data looks a lot more like the data you have in your programs than relational data does
•
schemaless
•
two documents don't need to have the same schema as two SQL rows do
•
where does MongoDB fit in the world?
•
two axis:
•
scalability and performance
•
memcached
•
scalable and has good performance, but offers little functionality
•
depth of functionality
•
Oracle
•
DB2
•
SQL Server
•
not known for being particularly scalable: easy to scale up but not easy to scale out (use commodity hardware)
•
MongoDB strikes the balance between these two
•
what is missing from MongoDB which classic RDBMS have?
•
no joins
•
each document is stored in a collection
•
the reason is: joins is one of the items which scales particularly poorly when you try to scale out
•
no transactions
•
sounds bad, but you often don't need them in applications which use MongoDB
•
because documents are hierarchicals, you get some of this functionality
•
and it also is the case in real-world RDBMS scenarios that you do not have transactions between separate databases anyway
•
what is included in MongoDB which RDBMS have?
•
indexes
•
secondary indexes
•
although these are challenging to get them to perform well on a system which is horizontally scalable
•
browser --> layout engine --> JavaScript engine
•
Firefox --> Gecko --> SpiderMonkey
•
Safari --> WebKit --> Nitro
•
Chrome --> WebKit --> V8
•
2013: Chrome --> Blink --> V8
•
Opera --> Presto --> Carakan
•
2013: Opera --> Blink --> V8
•
Internet Explorer --> Trident --> Chakra
•
layout engines
•
Gecko
•
Firefox
•
KHTML
•
Konqueror
•
Trident
•
Internet Explorer
•
WebKit
•
Safari
•
Google Chrome (2013: discontinued using it)
•
Presto
•
Opera (2013: phased it out)
•
Blink
•
Chrome
•
April 2013: Google forked from WebKit
•
even before the split, Chrome never used WebKit in same way as Safari, e.g. Chrome ignored WebKit's JavaScriptCore and used V8 instead
•
Opera
•
July 2013: Opera switched to Blink
•
Opera 15+
•
Webview (Android)
•
as of 4.4
•
JavaScript engines
•
SpiderMonkey
•
1995: Brendan Eich, Netscape
•
C/C++
•
SpiderMonkey name has remained the same but modern engine is unrecognizable from 1995 engine
•
JIT compilers for SpiderMonkey
•
TraceMonkey
•
JägerMonkey
•
IonMonkey (current)
•
translates SpiderMonkey bytecode into a control flow graph
•
default engine in Firefox since version 18
•
Rhino
•
1997: Netscape
•
developed entirely in Java
•
separate from the SpiderMonkey
•
Apple Safari 4's Nitro
•
Google Chrome's V8 engine
•
converts JavaScript into classes
•
works in compiled and interpreted mode
•
intended for server-side applications
•
no built-in support for web browser objects
•
JavaScriptCore
•
Apple forked KJS (Konqueror) to create JavaScriptCore for WebKit (layout engine)
•
2008 WebKit gets SquirrelFish
•
SquirrelFish Extreme, Nitro, Nitro Extreme, compiles JavaScript directly to machine code (like V8)
•
JavaScriptCore source code resides in the WebKit source tree
•
V8
•
2008 with Chrome 2, in response to Nitro
•
compiles JavaScript to native machine code
•
intended to be used both in a browsers, e.g. Chrome and Chromium (open source web browser project from which Google Chrome draws its source code, the browsers share the majority of code and features)
•
goal for Chrome is to be a "a tabbed window manager, or shell for the web, as opposed to it being a traditional browser application"
•
Chakra
•
as of Internet Explorer 9
•
uses GPU for 3D graphics and video
•
MongoDB from 10,000 feet
•
clients
•
web browsers
•
any client sending requests, e.g. consuming REST API
•
application server
•
running node.js
•
C++ program that you control using V8 JavaScript
•
all code for it are written in JavaScript
•
server responds to requests from clients
•
this application needs to store persistent data, that is where MongoDB comes in
•
MongoDB server
•
written in C++
•
application server acts as client and communicates with MongoDB server which is listening for requests
•
Mongo Shell
•
has similarities with node.js
•
C++ application that you control with V8
•
makes requests to MongoDB
•
looking at the data
•
debugging your application
•
the driver
•
handles all the connections, fail over
•
provides API which handles the communication to MongoDB