Couch DB
Mohammad Hossain Amini
Advanced Database
Dr.Niyazi
1
2.0
2
What is Apache CouchDB?
CouchDB Is..
• An Apache Project.
• An Open-Source Document-Oriented Database.
• it uses JSON to store data.
• Written in Erlang.
• CouchDB project was created in April 2005 by Damien Katz.
• CouchDB became an Apache Software Foundation project in 2008.
• In early 2012, Katz left the project to focus on Couchbase Server.
3
Technical Overview
4
Document Storage
• A CouchDB server hosts named databases, which store documents.
• CouchDB provides a RESTful HTTP API for reading and updating (add, edit, delete) database documents.
• Document fields are uniquely named and contain values of varying types (text, number, boolean, lists, etc).
• The CouchDB document update model is lockless and optimistic.
• CouchDB read operations use a Multi-Version Concurrency Control (MVCC).
• The database never contains partially saved or edited documents.
• Document updates (add, edit, delete) are serialized, except for binary blobs which are written concurrently.
• Documents are indexed in B-trees by their name (DocID) and a Sequence ID.
5
The CAP Theorem
• Consistency: All database clients see the same data, even with concurrent updates.
• Availability: All database clients are able to access some version of the data.
• Partition tolerance: The database can be split over multiple servers.
6
MapReduce
7
Anatomy of a view request
8
MapReduce Views
9
{ “user” : “Chris”,
“points” : 3 }
{ “user” : “Joe”,
“points” : 10 }
{ “user” : “Alice”,
“points” : 5 }
{ “user” : “Mary”,
“points” : 9 }
{ “user” : “Bob”,
“points” : 7 }
{ “key” : “Alice”,
“value” : 5 }
{ “key” : “Bob”,
“value” : 7 }
{ “key” : “Chris”,
“value” : 3 }
{ “key” : “Joe”,
“value” : 10 }
{ “key” : “Mary”,
“value” : 9 }
function(doc) {
if (doc.user && doc.points) {
emit(doc.user, doc.points);
}
}
MAP
Everyone: 34
function(keys, values, rereduce) {
return sum(values);
}
Reduce
Replication
10
Introduction to Replication
• One of CouchDB’s strengths is the ability to synchronize two copies of the same database.
• CouchDB will compare the source and the destination database(Changes Feeds).
• Master - Master replication.
• Local documents are never replicated (non-replicating).
• The document will only be replicated if the filter function returns true.
11
Migrating Data to Clients
• Cloudant
• PouchDB
• TouchDB
• Couchbase Lite
12
Examples
13
Document & Query
14
Document Query
Fauxton
15
16
http://127.0.0.1:5984/_utils/
17

Couch db

  • 1.
    Couch DB Mohammad HossainAmini Advanced Database Dr.Niyazi 1 2.0
  • 2.
  • 3.
    CouchDB Is.. • AnApache Project. • An Open-Source Document-Oriented Database. • it uses JSON to store data. • Written in Erlang. • CouchDB project was created in April 2005 by Damien Katz. • CouchDB became an Apache Software Foundation project in 2008. • In early 2012, Katz left the project to focus on Couchbase Server. 3
  • 4.
  • 5.
    Document Storage • ACouchDB server hosts named databases, which store documents. • CouchDB provides a RESTful HTTP API for reading and updating (add, edit, delete) database documents. • Document fields are uniquely named and contain values of varying types (text, number, boolean, lists, etc). • The CouchDB document update model is lockless and optimistic. • CouchDB read operations use a Multi-Version Concurrency Control (MVCC). • The database never contains partially saved or edited documents. • Document updates (add, edit, delete) are serialized, except for binary blobs which are written concurrently. • Documents are indexed in B-trees by their name (DocID) and a Sequence ID. 5
  • 6.
    The CAP Theorem •Consistency: All database clients see the same data, even with concurrent updates. • Availability: All database clients are able to access some version of the data. • Partition tolerance: The database can be split over multiple servers. 6
  • 7.
  • 8.
    Anatomy of aview request 8
  • 9.
    MapReduce Views 9 { “user”: “Chris”, “points” : 3 } { “user” : “Joe”, “points” : 10 } { “user” : “Alice”, “points” : 5 } { “user” : “Mary”, “points” : 9 } { “user” : “Bob”, “points” : 7 } { “key” : “Alice”, “value” : 5 } { “key” : “Bob”, “value” : 7 } { “key” : “Chris”, “value” : 3 } { “key” : “Joe”, “value” : 10 } { “key” : “Mary”, “value” : 9 } function(doc) { if (doc.user && doc.points) { emit(doc.user, doc.points); } } MAP Everyone: 34 function(keys, values, rereduce) { return sum(values); } Reduce
  • 10.
  • 11.
    Introduction to Replication •One of CouchDB’s strengths is the ability to synchronize two copies of the same database. • CouchDB will compare the source and the destination database(Changes Feeds). • Master - Master replication. • Local documents are never replicated (non-replicating). • The document will only be replicated if the filter function returns true. 11
  • 12.
    Migrating Data toClients • Cloudant • PouchDB • TouchDB • Couchbase Lite 12
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.