Introduction To MongoDB

1,157 views
1,104 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
1,157
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
34
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction To MongoDB

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

×