Slides from a presentation I held at the MongoDB User Group Düsseldorf. It gives an introduction to MongoDB and Node.js and how and why to get them running together.
the same data format • JSON and JavaScript all around • easy to get running • easy to learn • vibrant communities • Open Source backed by strong enterprises Why do I like the combination of MongoDB and Node.js?
data persistence • uses document oriented storage • offers a rich query language • written in C++ • makes use of JavaScript (in Mongo Shell and Map/Reduce) • Open Source (backed by 10gen) What is MongoDB?
is made up of fields with each field having a key and a value • each value has a datatype • different documents may have different fields • MongoDB uses BSON as storage format • drivers for MongoDB translate between BSON and JSON What is document oriented storage?
objects, arrays, numbers, strings, booleans, and null. • suitable for data storage and sending information over networks • the choice for data transport via XMLHttpRequest (XHR) or WebSocket What is JSON?
functions • invented back in 1995 by Brendan Eich • influenced by some other languages, but has little in common with Java • standardized as ECMAScript by the Ecma International standards organization • the programming language for web apps • used in many non-browser environments What is JavaScript?
just a few basic types of objects • the type of an object is evaluated at runtime (dynamic type system) • every object has a 'constructor' and a 'prototype' (for prototypical inheritance) • there are no classes or interfaces (yet) • an object can have fields, each field holds another object What is 'object oriented' in JavaScript?
arguments • higher order functions are supported • anonymous functions are supported • variables are declared in function scope • lexical scoping is used • an inner function has access to variables in the surrounding scope (i.e. 'closures') What about 'first class functions' in JavaScript? 'What this means is that an inner function always has access to the vars and parameters of its outer function, even after the outer function has returned.'
networked computer programs using JavaScript • invented in 2009 by Ryan Dahl • based on libuv, a high performance evented I/O library • based on Google's JavaScript engine V8 • written in C / C++ / JavaScript • Open Source (backed by Joyent et al.) What is Node.js?
• a debugger • a core API focused on event handling, networking, file system, streams, module loading and some more • a whole lot of documentation • a full featured package manager ('npm') What does Node.js provide?
callbacks • the event loop • consistency of style • keep the core small • modules What are the core concepts of Node.js? 'In event-driven programming, an application expresses interest in certain events and responds to them when they occur.'
a vast amount of these! • many modules can be used both in the browser and in Node.js • some modules provide command line functionality • all of them are managed with 'npm' How can the core of Node.js be extended?
• define / manage dependencies • search for modules • install / update / uninstall modules • publish your module • versioning • control lifecycle of your program • etc... What can I do with 'npm'?
https://github. com/mongodb/node-mongodb-native • in an asynchronous manner • with callback functions • with JSON / JavaScript objects • with query objects similar / identical to those of Mongo Shell How do I use MongoDB with Node.js?
http://mongoosejs. com/ • allows model / schema definition • gives you simplified queries • supports validation, default values, getters / setters and a lot more • in an asynchronous manner with callback functions • but more 'object oriented' What about an ODM for Node.js and MongoDB?
• http://javascript.crockford.com/ • http://en.wikipedia.org/wiki/First-class_function • http://nodejs.org/ • http://nodemanual.org/latest/ • http://nikhilm.github.com/uvbook/ • http://www.typescriptlang.org/ • http://coffeescript.org/ Where did I get this from?