Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MongoDB DUS: MongoDB and Node.js

MongoDB DUS: MongoDB and Node.js

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.

Avatar for Gerd Jungbluth

Gerd Jungbluth

December 20, 2012
Tweet

More Decks by Gerd Jungbluth

Other Decks in Programming

Transcript

  1. • perfect match for modern data driven applications • share

    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?
  2. • on desktop computers • on servers • in the

    cloud • running Linux • running Unix • running Mac OS X • running Microsoft Windows Where can I deploy MongoDB / Node.js?
  3. • a database system • designed for fast, distributed, scalable

    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?
  4. • information is stored in distinct documents • a document

    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?
  5. • it's 'JavaScript Object Notation' • a syntax for serializing

    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?
  6. • a lightweight, interpreted, object- oriented programming language with first-class

    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?
  7. • everything in JavaScript is an object • there are

    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?
  8. • functions are objects • functions can be passed as

    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.'
  9. • a software platform • designed to build fast, efficient,

    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?
  10. • a programming language • a 'foo / bar /

    baz framework' • a web server • an application server • a standard • a purchasable product What is Node.js not?
  11. • an executable (i.e. 'node' / 'node.exe') • a REPL

    • 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?
  12. • asynchronous code execution • non-blocking I/O • events •

    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.'
  13. • with user contributed modules (or packages) • there is

    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?
  14. • a lot :-) • describe your program / module

    • 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'?
  15. • 'npm install mongodb' • let's have a look at

    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?
  16. • 'npm install mongoose' • let's have a look at

    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?
  17. • http://nodestack.org/ • http://www.mongodb.org/ • http://bsonspec.org/ • http://www.json.org/ • https://developer.mozilla.org/en-US/docs/JavaScript

    • 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?