CouchDB

> Database

1 - About

NoSQL database

Everything in CouchDB is javascript.

CouchDB uses optimistic concurrency control, which does not use any locking system.

Advertising

3 - Document

Document = set of key/value pairs

"Subject": "I like Rixt" 
"Author": "Nico" 
"PostedDate": "5/27/2013" 
"Tags": ["love", "fact", "wife"]
"Body": "Just to say that i love my wife"

4 - Update

  • Full Consistency within a document
  • Lock-free concurrency (Optimistic – attempts to edit dirty data fail)
  • No multi-row transactions.
    • A Transaction is a sequence of related record updates
    • Entire sequence considered ACID

5 - Views

Map Reduce Views:

{
   "_id":"_design/company",
   "_rev":"12345",
   "language":"javascript",
   "views":{
      "all":{
         "map":"function(doc) {if (doc.Type=='customer’) emit(null, doc) }"
      },
      "by_lastname":{
         "map":"function(doc) {if (doc.Type=='customer’) emit(doc.LastName, doc) }"
      },
      "total_purchases":{
         "map":"function(doc) { if (doc.Type=='purchase’) emit(doc.Customer, doc.Amount) }",
         "reduce":"function(keys, values) { return sum(values) }"
      }
   }
}