An introduction to
But First, A Little About MeMy name’s Lee Theobald. Hello!Twitter: @LeesyNever updated blog: http://www.ltheobald.co.uk/I’m a developer at a small search company in Cambridge called Open Objects.
So what is MongoDB?
NoSQL databaseThe name is short for humongousOpen source with development lead by 10Gen (http://www.10gen.com)Document BasedSchema-lessHighly ScalableMapReduceReplication & Auto Sharding
Document StoreData is stored in the form of JSON data.{"_id" : ObjectId("4ccbfc75bd163019417c27f8"),"title": “Hello World! ","author": {"firstname": "Joe","lastname": "Bloggs"    },"tags": ["test", "foo", "bar"]}
Familiar StructureMongoDB instances contain a number of databases which in turn contain a number of collections.Think of MySQL with it’s databases & tables.But collections can also be nested.  E.g.customer_a(Database)logs_201009		(Collection)top_queries(Collection)
Inserts – Easy As Pie!use cookbook;db.desserts.save({   name: "Cherry Pie",   ingredients: ["cherries", "pie"],cooking_time: 30});
Searching – A Piece Of Cakedb.recipes.find({cooking_time: { “$gte”: 10, “$lt”: 30}})db.recipes.findOne()
Some More Advanced Query SyntaxLimitingdb.find().limit(10);Skippingdb.find(	).skip(5);Sortingdb.find({…}).sort({cooking_time: “-1”});Cursorsvar cur = db.find({…}).cursor()cur.forEach( function(x) { print(tojson(x)) });
MapReduceGreat way of doing bulk manipulation or aggregation.2 or 3 functions written in JavaScriptthat execute on the server.An example use could be generating a list of top queries from some search logs.
Map FunctionTakes some input of the form of key/value pairs.Does something with thatReturns 0 or more key/value pairsmap = function() {   if (!this.query) {       return;   }   emit (this.query, {count: 1});}
Reduce FunctionTakes the results from the map functionDoes something (normally combine the results)Produces output in key/value pairsreduce = function(key, values) {var count = 0;values.forEach(function(v) {       count += v[‘count’];    }   return {count: count;}}
Replica SetsMaster/Slave configurationIf your primary server goes down, one of the secondary ones takes over.
Auto Sharding
But Why Not Try It YourselfDownload it at: http://www.mongodb.orgOnline tutorial at:http://www.mongodb.org/display/DOCS/TutorialSome handy MongoDB sites:MongoDB Cookbook: http://cookbook.mongodb.org/Kyle Banker’s blog: http://kylebanker.com/blog/
Thanks For Listening.Any (easy)Questions?

Introduction To MongoDB

  • 1.
  • 2.
    But First, ALittle About MeMy name’s Lee Theobald. Hello!Twitter: @LeesyNever updated blog: http://www.ltheobald.co.uk/I’m a developer at a small search company in Cambridge called Open Objects.
  • 3.
    So what isMongoDB?
  • 4.
    NoSQL databaseThe nameis short for humongousOpen source with development lead by 10Gen (http://www.10gen.com)Document BasedSchema-lessHighly ScalableMapReduceReplication & Auto Sharding
  • 5.
    Document StoreData isstored in the form of JSON data.{"_id" : ObjectId("4ccbfc75bd163019417c27f8"),"title": “Hello World! ","author": {"firstname": "Joe","lastname": "Bloggs" },"tags": ["test", "foo", "bar"]}
  • 6.
    Familiar StructureMongoDB instancescontain a number of databases which in turn contain a number of collections.Think of MySQL with it’s databases & tables.But collections can also be nested. E.g.customer_a(Database)logs_201009 (Collection)top_queries(Collection)
  • 7.
    Inserts – EasyAs Pie!use cookbook;db.desserts.save({ name: "Cherry Pie", ingredients: ["cherries", "pie"],cooking_time: 30});
  • 8.
    Searching – APiece Of Cakedb.recipes.find({cooking_time: { “$gte”: 10, “$lt”: 30}})db.recipes.findOne()
  • 9.
    Some More AdvancedQuery SyntaxLimitingdb.find().limit(10);Skippingdb.find( ).skip(5);Sortingdb.find({…}).sort({cooking_time: “-1”});Cursorsvar cur = db.find({…}).cursor()cur.forEach( function(x) { print(tojson(x)) });
  • 10.
    MapReduceGreat way ofdoing bulk manipulation or aggregation.2 or 3 functions written in JavaScriptthat execute on the server.An example use could be generating a list of top queries from some search logs.
  • 11.
    Map FunctionTakes someinput of the form of key/value pairs.Does something with thatReturns 0 or more key/value pairsmap = function() { if (!this.query) { return; } emit (this.query, {count: 1});}
  • 12.
    Reduce FunctionTakes theresults from the map functionDoes something (normally combine the results)Produces output in key/value pairsreduce = function(key, values) {var count = 0;values.forEach(function(v) { count += v[‘count’]; } return {count: count;}}
  • 13.
    Replica SetsMaster/Slave configurationIfyour primary server goes down, one of the secondary ones takes over.
  • 14.
  • 15.
    But Why NotTry It YourselfDownload it at: http://www.mongodb.orgOnline tutorial at:http://www.mongodb.org/display/DOCS/TutorialSome handy MongoDB sites:MongoDB Cookbook: http://cookbook.mongodb.org/Kyle Banker’s blog: http://kylebanker.com/blog/
  • 16.
    Thanks For Listening.Any(easy)Questions?