Your SlideShare is downloading. ×
  • Like
An introduction to CouchDB
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

An introduction to CouchDB

  • 10,264 views
Published

This is a talk I presented at University Limerick to give people an introduction into CouchDB. …

This is a talk I presented at University Limerick to give people an introduction into CouchDB.

What is it? How does it generally work? Introducing new concepts, etc.

Published in Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
10,264
On SlideShare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
417
Comments
1
Likes
26

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide





















































Transcript

  • 1. An introduction to #CouchDB Sit back and relax @davidcoallier, University Limerick 2010
  • 2. WTF IS COUCH? - Highly concurrent database server - Schema free, document based database - RESTFul API - Map/Reduce Views generation - EASY replication (like... really)
  • 3. ... AGAIN.. WTF?!
  • 4. HISTORY CLASS TIME!
  • 5. 32 CouchDB servers 2 datacenters SSL based user auth, sharding, etc. This is the only BBC transparent logo I found and it’s not BBC World News using CouchDB but BBC. See: http://www.erlang-factory.com/conference/London2009/speakers/endafarrell
  • 6. Ubuntu One
  • 7. mozilla.org IBM Apple myspace.com ebay meebo oh so many more.
  • 8. DOCUMENT BASED KEY/VALUE STORE...
  • 9. key value name david email e@e.com phones Array createdAt timetsamp
  • 10. DOCUMENT BASED WHAT? - Dictionary of data - JSON Objects - A doc can have attachments - Auto generated IDs (CLAP NOW) - Revisions (THAT’S RIGHT..)
  • 11. DOCUMENT { "_id": "3fc3b3bf3c101e15fa7d08e2ecf9c900", "_rev": "1-34c5c7adcf1fdb8898498d1e6b64ebdd", "firstname": "David", "email": "david@echolibre.com" }
  • 12. DOCUMENT { "_id": "3fc3b3bf3c101e15fa7d08e2ecf9c900", "_rev": "1-34c5c7adcf1fdb8898498d1e6b64ebdd", "firstname": "David", "email": "david@echolibre.com", "phones": { "mobile": "086x209x69", "home": "none" }, "createdAt": "2009-09-16T22:12:43Z" }
  • 13. key value name david email e@e.com phones Array createdAt timetsamp
  • 14. WHAT ABOUT MY CRUD? - Create PUT /db/docid - Retrieve GET /db/docid - Update POST /db/docid - Delete DELETE /db/docid
  • 15. VIEWS - Persistent representation of docs - Prod is solid. No _temp shit. - Javascript, Erlang, Python, wtf ever.
  • 16. MAP/REDUCE ...
  • 17. JAVASCRIPT
  • 18. MAP map: function(doc) { if (doc.firstname) { emit(doc.firstname, doc); } }
  • 19. MAP %% Map Function fun({Doc}) -> case {proplists:get_value(<<"firstname">>, Doc)} of {undefined} -> false; {Name} -> Emit(Name, Doc); _ -> ok end end.
  • 20. fun({Doc}) -> Emitter = fun(Doc) -> Name = proplists:get_value(<<"name">>, Doc, null), Emit(Name, Doc) end, HasRequiredFields = fun(Doc) -> case {proplists:is_defined(<<"firstname">>, Doc)} of {true} -> Emitter(Doc); _-> false end end, HasRequiredFields(Doc) end.
  • 21. MAP/REDUCE EXAMPLE
  • 22. MAP { "_id": "3fc3b3bf3c101e15fa7d08e2ecf9c900", "_rev": "1-34c5c7adcf1fdb8898498d1e6b64ebdd", "firstname": "David", "email": "david@echolibre.com", "phones": { "mobile": "086x209x69", "home": "none" }, "createdAt": "2009-09-16T22:12:43Z", "tags": ["cool", "php", "couchdb", "skynet"] }
  • 23. MAP map: function(doc) { if (doc.tags && docs.tags.length > 0) { for (var i = 0; i < doc.tags.length; i++) { emit(doc.tags[i], 1); } } }
  • 24. REDUCE map: function(doc) { if (doc.tags && docs.tags.length > 0) { for (var i = 0; i < doc.tags.length; i++) { emit(doc.tags[i], 1); } } }, reduce: function(tag, counts) { int sum = 0; for(var i = 0; i < counts.length; i++) { sum += counts[i]; } return sum; }
  • 25. REDUCE function(tag, counts) { int sum = 0; for(var i = 0; i < counts.length; i++) { sum += counts[i]; } return sum; }
  • 26. REDUCE { "total_rows":4, "rows":[ { "key":"cool", "value":1}, { "key":"php", "value":1}, { "key":"couchdb", "value":1}, { "key":"skynet", "value":1}, ] }
  • 27. REDUCE TRICKS map: function(doc) { if (doc.tags && docs.tags.length > 0) { for (var i = 0; i < doc.tags.length; i++) { emit(doc.tags[i], 1); } } } reduce: "_count"
  • 28. REDUCE { "total_rows":4, "rows":[ { "key":"cool", "value":1}, { "key":"php", "value":1}, { "key":"couchdb", "value":1}, { "key":"skynet", "value":1}, ] }
  • 29. REDUCE map: function(doc) { if (doc.tags && docs.tags.length > 0) { for (var i = 0; i < doc.tags.length; i++) { emit(doc.tags[i], "yer ma"); } } }, reduce: function (tag, count) { return sum(tag); }
  • 30. THEN...
  • 31. BEWARE OF REDUCE VALUES
  • 32. REPLICATION It fuckin’ rules.
  • 33. REPLICATION Easy (See later futon ;-)) Continuous... or not :P Replicates your views Replicate only what you need (filter?)
  • 34. REPLICATION curl -X POST http://localhost:5984/_replicate '{"source":"/dbname", "target": "http://localhost:5555/otherdb", "continuous": true}'
  • 35. REPLICATION Source The boss Target changes? watcha need?? target needs x, y, z save them
  • 36. REPLICATION MASTER / SLAVES
  • 37. REPLICATION MASTER / SLAVES
  • 38. REPLICATION MULTI MASTER
  • 39. REPLICATION MULTI MASTER
  • 40. REPLICATION USE CASE Automated job to validate and test data and do bunch of shits
  • 41. FUTON
  • 42. FUTON
  • 43. NOTE TO SELF. Show them. Open up CouchDBX
  • 44. COOL THINGS Authorization CouchDB Lucene Lounge CouchDBX Couchio Cloudant A bunch of random bits and pieces
  • 45. COMPLETE SHITE COMING UP eas r e id sha W le! NO p s peo cus Dis
  • 46. CONCEPTS AND IDEAS Graph Theory ... ss ion u a disc t d star tr y an
  • 47. CONCEPTS AND IDEAS Ghost Replication ... ss ion u a disc t d star tr y an
  • 48. CONCEPTS AND IDEAS Shared Index Replication ... ss ion u a disc t d star tr y an
  • 49. QUESTIONS?
  • 50. ME! MEEE!!! @davidcoallier david@echolibre.com
  • 51. THANKS
  • 52. LINKS - https://nosqleast.com/2009/slides/miller-couchdb.pdf - http://couch.io - http://cloudant.com - http://wiki.apache.org/couchdb/CouchDB_in_the_wild - irc://couchdb@freenode.net (Bug jan___ ;-))