SlideShare a Scribd company logo
CouchDB and the web
Knut O. Hellan twitter.com/knuthellan knuthellan.com
NoSQL
NoSQL Freedom of choice Right tool for the job Use relational databases when appropriate
Flavor of the week Lightweight key-value:  Graph: Document stores:  Server spanning:    More
CouchDB Overview
Pros and cons RESTful JSON API Schema free Incremental map reduce views Incremental bi-directional replication
Pros and cons Robust append-only File backup with cp and tar Scalable?
CouchDB views
Our database
Our database { "_id": "123bc00725fc9f831209440793001bb6", "_rev": "3-f30fca1f7fb4f387207e4756795aac74", "author": "jchris", "tweet": "This weekend just happened to be a good time for me to hack. Node.js CouchDB and Twitter, makes me feel like I'm part of #nodeko but I'm not", "type": "tweet" }
View Design
Default mapper function(doc) {   emit(null, doc); }
Indexer function(doc) {    if (!doc.tweet) return;    var clean_text = doc.tweet.replace(/\W/g, ' ').replace(/  /g, ' ');   var lower_text = clean_text.toLowerCase();   var text_vector = lower_text.split(/ /);   for (var i in text_vector) {     var word = text_vector[i];     if (word.length > 2) emit(word, doc._id);   } }
The mapper output http://localhost:5984/news/_design/parser/_view/index {"total_rows":50,"offset":0,"rows":[ {"id":"123bc00725fc9f83120944079300093e","key":"9xmyxw","value":1}, {"id":"123bc00725fc9f831209440793000f46","key":"a6exod","value":1}, {"id":"123bc00725fc9f831209440793000f46","key":"and","value":1}, {"id":"123bc00725fc9f831209440793001bb6","key":"and","value":1}, {"id":"123bc00725fc9f83120944079300093e","key":"are","value":1}, http://localhost:5984/news/_design/parser/_view/index?key=%22couchdb%22 {"total_rows":50,"offset":11,"rows":[ {"id":"123bc00725fc9f83120944079300093e","key":"couchdb","value":1}, {"id":"123bc00725fc9f831209440793000f46","key":"couchdb","value":1}, {"id":"123bc00725fc9f831209440793001bb6","key":"couchdb","value":1} ]}
Add reducer function(keys, values, rereduce) {   return sum(values); }   http://localhost:5984/news/_design/parser/_view/index {"rows":[ {"key":null,"value":50} ]}  http://localhost:5984/news/_design/parser/_view/index?key=%22couchdb%22{"rows":[ {"key":null,"value":3} ]}
Grouping http://localhost:5984/news/_design/parser/_view/index?group_level=1 {"rows":[ {"key":"9xmyxw","value":1}, {"key":"a6exod","value":1}, {"key":"and","value":2}, {"key":"are","value":1},
CouchDB replication
Futon Replication
Replication Modes - Copy or replicate once   - Continuous replication - Filtered replication
Multi-Couch
Offline replication - Mobile phone - Notebook or tablet and the cloud
Conflicts Multi-master => possible conflicts All masters will agree Conflict information kept in revision history
Filtered Replication function(doc, req) { if (doc.type && doc.type == "foo") { return true; } else { return false; } }
Filtered Replication { "_id":"myddoc", "filters": { "myfilter": "function goes here" } }
Filtered Replication {  "source":"http://example.org/example-database",  "target":"http://admin:password@127.0.0.1:5984/example-database",   "filter":"myddoc/myfilter"}
CouchDB scaling
Alternatives - CouchDB lounge    -    - Pillow
Pillow - Reuses CouchDB functionality   - Transparent for users   - Automatic resharding
Pillow
Pillow
Pillow
Pillow
Pillow
CouchDB lessons learned
CouchDB Experience Map Reduce based views are powerful View experimentation in Futon Three-way multi-master replication Replication monitor
CouchDB Experience EC2 External middleware still useful Duck typing matches CouchDB's JSON
Now what? Install and play with CouchDB Visit couchdb.apache.org Visit knuthellan.com
relax

More Related Content

PPT
Html5, css3, canvas, svg and webgl
PPT
Real-Time Python Web: Gevent and Socket.io
PPTX
DJUGL - Django and AWS Lambda
PDF
3 Steps to Make Better & Faster Frontends
PDF
Big Frontends Made Simple
PDF
Scaling Rails Sites by default
PPTX
Writing automation tests with python selenium behave pageobjects
Html5, css3, canvas, svg and webgl
Real-Time Python Web: Gevent and Socket.io
DJUGL - Django and AWS Lambda
3 Steps to Make Better & Faster Frontends
Big Frontends Made Simple
Scaling Rails Sites by default
Writing automation tests with python selenium behave pageobjects

Viewers also liked (9)

PDF
Wrapper induction construct wrappers automatically to extract information f...
PDF
Couch Db In 60 Minutes
PDF
Named Entities
PDF
Couch db
PDF
Python RESTful webservices with Python: Flask and Django solutions
PPTX
Securing RESTful APIs using OAuth 2 and OpenID Connect
PDF
Using Document Databases with TYPO3 Flow
PPT
Learn REST API with Python
PPTX
JSON and REST
Wrapper induction construct wrappers automatically to extract information f...
Couch Db In 60 Minutes
Named Entities
Couch db
Python RESTful webservices with Python: Flask and Django solutions
Securing RESTful APIs using OAuth 2 and OpenID Connect
Using Document Databases with TYPO3 Flow
Learn REST API with Python
JSON and REST
Ad

Similar to Couch db and_the_web (20)

PDF
CouchDB at JAOO Århus 2009
PPT
No sql Database
ODP
Intro to CouchDB
PDF
CouchDB Open Source Bridge
PDF
Couchdb Nosql
PDF
Vidoop CouchDB Talk
PDF
CouchDB
PDF
Advanced CouchDB Rotterdam.rb July 2010
PPTX
Cluster of unreliable commodity hardware (couchdb) (2)
PPTX
Couch DB
KEY
OSCON 2011 CouchApps
PPTX
Intro to CouchDB
PDF
CouchDB Talk JChris NYC
KEY
NoSQL: Why, When, and How
PPT
Couch db
PPTX
Querying NoSQL with SQL - MIGANG - July 2017
PDF
NoSQL and CouchDB: the view from MOO
KEY
Couchdb: No SQL? No driver? No problem
PDF
CouchDB Mobile - From Couch to 5K in 1 Hour
PDF
CouchDB
CouchDB at JAOO Århus 2009
No sql Database
Intro to CouchDB
CouchDB Open Source Bridge
Couchdb Nosql
Vidoop CouchDB Talk
CouchDB
Advanced CouchDB Rotterdam.rb July 2010
Cluster of unreliable commodity hardware (couchdb) (2)
Couch DB
OSCON 2011 CouchApps
Intro to CouchDB
CouchDB Talk JChris NYC
NoSQL: Why, When, and How
Couch db
Querying NoSQL with SQL - MIGANG - July 2017
NoSQL and CouchDB: the view from MOO
Couchdb: No SQL? No driver? No problem
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB
Ad

Couch db and_the_web

  • 2. Knut O. Hellan twitter.com/knuthellan knuthellan.com
  • 4. NoSQL Freedom of choice Right tool for the job Use relational databases when appropriate
  • 5. Flavor of the week Lightweight key-value: Graph: Document stores: Server spanning:   More
  • 7. Pros and cons RESTful JSON API Schema free Incremental map reduce views Incremental bi-directional replication
  • 8. Pros and cons Robust append-only File backup with cp and tar Scalable?
  • 11. Our database { "_id": "123bc00725fc9f831209440793001bb6", "_rev": "3-f30fca1f7fb4f387207e4756795aac74", "author": "jchris", "tweet": "This weekend just happened to be a good time for me to hack. Node.js CouchDB and Twitter, makes me feel like I'm part of #nodeko but I'm not", "type": "tweet" }
  • 13. Default mapper function(doc) {   emit(null, doc); }
  • 14. Indexer function(doc) {   if (!doc.tweet) return;   var clean_text = doc.tweet.replace(/\W/g, ' ').replace(/  /g, ' ');   var lower_text = clean_text.toLowerCase();   var text_vector = lower_text.split(/ /);   for (var i in text_vector) {     var word = text_vector[i];     if (word.length > 2) emit(word, doc._id);   } }
  • 15. The mapper output http://localhost:5984/news/_design/parser/_view/index {"total_rows":50,"offset":0,"rows":[ {"id":"123bc00725fc9f83120944079300093e","key":"9xmyxw","value":1}, {"id":"123bc00725fc9f831209440793000f46","key":"a6exod","value":1}, {"id":"123bc00725fc9f831209440793000f46","key":"and","value":1}, {"id":"123bc00725fc9f831209440793001bb6","key":"and","value":1}, {"id":"123bc00725fc9f83120944079300093e","key":"are","value":1}, http://localhost:5984/news/_design/parser/_view/index?key=%22couchdb%22 {"total_rows":50,"offset":11,"rows":[ {"id":"123bc00725fc9f83120944079300093e","key":"couchdb","value":1}, {"id":"123bc00725fc9f831209440793000f46","key":"couchdb","value":1}, {"id":"123bc00725fc9f831209440793001bb6","key":"couchdb","value":1} ]}
  • 16. Add reducer function(keys, values, rereduce) {   return sum(values); }   http://localhost:5984/news/_design/parser/_view/index {"rows":[ {"key":null,"value":50} ]}  http://localhost:5984/news/_design/parser/_view/index?key=%22couchdb%22{"rows":[ {"key":null,"value":3} ]}
  • 17. Grouping http://localhost:5984/news/_design/parser/_view/index?group_level=1 {"rows":[ {"key":"9xmyxw","value":1}, {"key":"a6exod","value":1}, {"key":"and","value":2}, {"key":"are","value":1},
  • 20. Replication Modes - Copy or replicate once   - Continuous replication - Filtered replication
  • 22. Offline replication - Mobile phone - Notebook or tablet and the cloud
  • 23. Conflicts Multi-master => possible conflicts All masters will agree Conflict information kept in revision history
  • 24. Filtered Replication function(doc, req) { if (doc.type && doc.type == "foo") { return true; } else { return false; } }
  • 25. Filtered Replication { "_id":"myddoc", "filters": { "myfilter": "function goes here" } }
  • 26. Filtered Replication {  "source":"http://example.org/example-database",  "target":"http://admin:password@127.0.0.1:5984/example-database",   "filter":"myddoc/myfilter"}
  • 28. Alternatives - CouchDB lounge    -   - Pillow
  • 29. Pillow - Reuses CouchDB functionality   - Transparent for users   - Automatic resharding
  • 36. CouchDB Experience Map Reduce based views are powerful View experimentation in Futon Three-way multi-master replication Replication monitor
  • 37. CouchDB Experience EC2 External middleware still useful Duck typing matches CouchDB's JSON
  • 38. Now what? Install and play with CouchDB Visit couchdb.apache.org Visit knuthellan.com
  • 39. relax