Introduction tomongodb

699 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
699
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction tomongodb

  1. 1. But First, A Little About Me  My name’s Lee Theobald. Hello!  Twitter: @Leesy  Never updated blog: http://www.ltheobald.co.uk/  I’m a developer at a small search company in Cambridge called Open Objects.
  2. 2.  NoSQL database  The name is short for humongous  Open source with development lead by 10Gen (http://www.10gen.com)  Document Based  Schema-less  Highly Scalable  MapReduce  Replication & Auto Sharding
  3. 3. Document Store  Data is stored in the form of JSON data. { "_id" : ObjectId("4ccbfc75bd163019417c27f8"), "title": “Hello World! ", "author": { "firstname": "Joe", "lastname": "Bloggs" }, "tags": ["test", "foo", "bar"] }
  4. 4. Familiar Structure  MongoDB 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)
  5. 5. Inserts – Easy As Pie! use cookbook; db.desserts.save({ name: "Cherry Pie", ingredients: ["cherries", "pie"], cooking_time: 30 });
  6. 6. Searching – A Piece Of Cake db.recipes.find({ cooking_time: { “$gte”: 10, “$lt”: 30} }) db.recipes.findOne()
  7. 7. Some More Advanced Query Syntax  Limiting  db.find().limit(10);  Skipping  db.find( ).skip(5);  Sorting  db.find({…}).sort({cooking_time: “-1”});  Cursors  var cur = db.find({…}).cursor()  cur.forEach( function(x) { print(tojson(x)) });
  8. 8. MapReduce  Great way of doing bulk manipulation or aggregation.  2 or 3 functions written in JavaScript that execute on the server.  An example use could be generating a list of top queries from some search logs.
  9. 9. Map Function  Takes some input of the form of key/value pairs.  Does something with that  Returns 0 or more key/value pairs map = function() { if (!this.query) { return; } emit (this.query, {count: 1}); }
  10. 10. Reduce Function  Takes the results from the map function  Does something (normally combine the results)  Produces output in key/value pairs reduce = function(key, values) { var count = 0; values.forEach(function(v) { count += v[‘count’]; } return {count: count;} }
  11. 11. Replica Sets  Master/Slave configuration  If your primary server goes down, one of the secondary ones takes over.
  12. 12. Auto Sharding
  13. 13. But Why Not Try It Yourself  Download it at: http://www.mongodb.org  Online tutorial at:http://www.mongodb.org/display/DOCS /Tutorial  Some handy MongoDB sites:  MongoDB Cookbook: http://cookbook.mongodb.org/  Kyle Banker’s blog: http://kylebanker.com/blog/

×