nosql and couchdb
DESCRIPTION
TRANSCRIPT
![Page 1: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/1.jpg)
![Page 2: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/2.jpg)
Who am I ?
-> My Name: João Cerdeira-> Team Leader-> An Agile enthusiast: Scrum / Kanban / Lean-> A true believer in OpenSource
http://twitter.com/jacerdeira [email protected]
![Page 3: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/3.jpg)
Disclamer
-> I understand your questions, but sometimes I don't have answers
-> I'm not a NoSQL Dogmatic, just an enthusiast about the new ways of storing information
-> I have worked with RDBMS for 12 years
![Page 4: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/4.jpg)
Everyone has their preferences
![Page 5: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/5.jpg)
I don't care if I/you will use SQL or NoSQL. I just want to deliver
better Services/Aplications to
the clients/users.
![Page 6: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/6.jpg)
Concepts & Theory
![Page 7: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/7.jpg)
Scale up vs Scale Down
![Page 8: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/8.jpg)
Performance VS Scalability
Latency VS Throughput
Availability VS Consistency
![Page 9: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/9.jpg)
Brewer's
CAPTheorem
![Page 10: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/10.jpg)
Choose only 2:
Consistency
Availabil ity
Partition Tolerance
At a given time in certain enviroment
![Page 11: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/11.jpg)
Consistency
Availability
PartitionTolerance
RDBMS
NoSQL
![Page 12: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/12.jpg)
Centralized System
In a centralized system (RDBMS) we don't have network partition
P in CAP
So we get:
Availability
Consistency
![Page 13: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/13.jpg)
-> A tomicity
-> Consistency
-> Isolated
-> Durability
![Page 14: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/14.jpg)
Distr ibuted System
In a distr ibuted system we (might) have network partition
P in CAP
So you can only pick one:
Availabil ity
Consistency
![Page 15: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/15.jpg)
CAP in practice
We have only two types of SystemsCP == CA (very similar)AP
So in a network partition we have only one choice
Consistency
Availabil ity
![Page 16: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/16.jpg)
-> Basically Available
-> Soft state
-> Eventually consistent
![Page 17: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/17.jpg)
Eventual Consistency
![Page 18: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/18.jpg)
How to Scale OutRDBMS ?http://capellaniaprimaria.blogspot.com/2011/02/concurso-deportivo-4-pregunta.html
![Page 19: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/19.jpg)
Partition
![Page 20: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/20.jpg)
Partition + Replication
![Page 21: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/21.jpg)
ORM Problems
![Page 22: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/22.jpg)
ORM Problems
What you want ?
Find/read a record/object
![Page 23: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/23.jpg)
ORM Problems
What you want ?
Find/read a record/object
What you get ?
A huge underground complexity
![Page 24: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/24.jpg)
Let Validateour Thoughts
![Page 25: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/25.jpg)
Let Validateour Thoughts
Do we need ACID for all solutions?
![Page 26: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/26.jpg)
Let Validateour Thoughts
Do we need ACID for all solutions?
When is Eventually Consistent enough ?
![Page 27: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/27.jpg)
Let Validateour Thoughts
Do we need ACID for all solutions?
When is Eventually Consistent enough ?
Different solutions require different needs
![Page 28: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/28.jpg)
Why NoSQL Appears ?
Because New Drivers Appears
(business or technical demand)
![Page 29: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/29.jpg)
New Drivers Behind NoSQL
Large amount of dataCommodity hardware
Scale Fast And CheapConstantly changing request (data)
![Page 30: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/30.jpg)
Why RDBMS aren't good enough ?
![Page 31: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/31.jpg)
Why RDBMS aren't good enough ?
Scalling reads in a RDBMS is hard
![Page 32: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/32.jpg)
Why RDBMS aren't good enough ?
Scalling reads in a RDBMS is hard
Scalling writes is impossible
![Page 33: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/33.jpg)
Think again
Do we really need a RDBMS ?
![Page 34: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/34.jpg)
Think again
Do we really need a RDBMS ?
Sometimes !
![Page 35: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/35.jpg)
Think again
Do we really need a RDBMS ?
Sometimes !
But a lot of times we don't !
![Page 36: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/36.jpg)
NoSQL
![Page 37: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/37.jpg)
How did NoSQL start ?
Google: BigtableAmazon: Dynamo
Facebook: CassandraLinkedIn: Valdemort
Yahoo: HBase (hadoop)
![Page 38: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/38.jpg)
OriginsGoogle : “How can we build a DB on top of Google File
System”
Paper: Bigtable A distributed store system for →
structured data, 2006
Amazon: “How can we build a distributed hash table for the data center”
Paper : Dynamo Amazon's highly available key-value →
store
![Page 39: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/39.jpg)
Different Types of NoSQL
Key-Value Stores
Document Databases
Column Databases
Graph Databases
![Page 40: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/40.jpg)
Key-Value Stores
Origin: Amazon's Dynamo paperData model : Collections of KV pairsImplementations: Dynamo, Voldemort, Membase,
Riak, RedisGood For:
- Large amount of data- Scale writes and reads- Fast- Programmer friendly
![Page 41: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/41.jpg)
Document Databases
Origin: Lotus NotesData model : Collections of DocumentsImplementations: CouchDB, MongoDB,
Amazon SimpleDBGood For:
- Human Data Structure - Programmer friendly- Rapid Development- Web friendly- CRUD
![Page 42: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/42.jpg)
Column Databases
Origin: Google's BigTable PaperData model : Column family – each row (at least in
theory) can have different configurationImplementations: BigTable, HBase, CassandraGood For:
- Large amount of data- scale writes like no other- High availability
![Page 43: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/43.jpg)
Graph Databases
Origin: Graph TheoryData model : Nodes and Relations,
both can have KV pairsImplementations: Neo4j, FlockDBGood For:
- resolve graph problems- Fast
![Page 44: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/44.jpg)
![Page 45: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/45.jpg)
Why I 'd choose CouchDB ?
-> Easy to understand documents-> Use standards web technologies-> Simple to install and configure-> Small footprint (works on mobile platforms)
-> Scales well (not for huge amount of data)
-> Replication in the core
![Page 46: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/46.jpg)
CouchDB Main Principals
Document Oriented Database
No rows or columns
Collection of JSON Documents
Schema-Free
![Page 47: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/47.jpg)
In CouchDB HTTP Rules
-> Everything is a HTTP Request-> We are used to know GET and POST-> But there are others:
-> PUT-> DELETE-> COPY
RESTful HTTP API
![Page 48: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/48.jpg)
Why JSON ?
-> Light and text-based data format-> Simple to parse-> Not verbose (comparing to xml)
-> Suitable for javascript frameworks (jquery)
-> Parsers available in almost all programming languages
![Page 49: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/49.jpg)
JSON Example{
make: "Ford" ,model : "Mustang" ,year: 2009,body: "Coupe" ,color: "Red" ,engine: {
gas_type: "Petrol" ,cubic_capacity: 4600
} ,previous_owners: [
{name: "John Smith" ,mileage: 1000
} ,{
name: "Jane Hunt" ,mileage: 2500
}]
}
![Page 50: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/50.jpg)
JSON Example{
make: "Ford" ,model : "Mustang" ,year: 2009,body: "Coupe" ,color: "Red" ,engine: {
gas_type: "Petrol" ,cubic_capacity: 4600
} ,previous_owners: [
{name: "John Smith" ,mileage: 1000
} ,{
name: "Jane Hunt" ,mileage: 2500
}]
}
![Page 51: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/51.jpg)
JSON Example{
make: "Ford" ,model : "Mustang" ,year: 2009,body: "Coupe" ,color: "Red" ,engine: {
gas_type: "Petrol" ,cubic_capacity: 4600
} ,previous_owners: [
{name: "John Smith" ,mileage: 1000
} ,{
name: "Jane Hunt" ,mileage: 2500
}]
}
![Page 52: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/52.jpg)
JSON Example{
make: "Ford" ,model : "Mustang" ,year: 2009,body: "Coupe" ,color: "Red" ,engine: {
gas_type: "Petrol" ,cubic_capacity: 4600
} ,previous_owners: [
{name: "John Smith" ,mileage: 1000
} ,{
name: "Jane Hunt" ,mileage: 2500
}]
}
![Page 53: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/53.jpg)
Example
![Page 54: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/54.jpg)
Create / Delete Database
$ curl http://127.0.0.1:5984
{"couchdb":"Welcome","version":"1.0.1"}
$ curl -X PUT http://127.0.0.1:5984/contacts
{"ok":true}
$ curl -X GET http://127.0.0.1:5984/_all_dbs
["contacts","_users"]
$ curl -X DELETE http://127.0.0.1:5984/contacts
{"ok":true}
![Page 55: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/55.jpg)
Manage Documents
$ curl -X PUT http://127.0.0.1:5984/contacts/joaocerdeira -d '{}'
{"ok":true,"id":"joaocerdeira","rev":"1-967a00dff5e02add41819138abb3284d"}
$ curl -X GET http://127.0.0.1:5984/contacts/joaocerdeira
{"_id":"joaocerdeira","_rev":"1-967a00dff5e02add41819138abb3284d"}
$ curl -X DELETE http://127.0.0.1:5984/contacts/joaocerdeira?rev=1-967a00dff5e02add41819138abb3284d
{"ok":true,"id":"joaocerdeira","rev":"2-eec205a9d413992850a6e32678485900"}
![Page 56: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/56.jpg)
Manage Documents
$ curl -X PUT http://127.0.0.1:5984/contacts/joaocerdeira -d'{"firstName":"Joao","lastName":"Cerdeira","email":"[email protected]"}'
{"ok":true,"id":"joaocerdeira","rev":"1-186fe12b748c40559e8f234d8e566c18"}
$ curl -X GET http://127.0.0.1:5984/contacts/joaocerdeira
{"_id":"joaocerdeira","_rev":"1-186fe12b748c40559e8f234d8e566c18","firstName":"Joao","lastName":"Cerdeira","email":"[email protected]"}
![Page 57: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/57.jpg)
Copy Documents
$ curl -X COPY http://127.0.0.1:5984/contacts/joaocerdeira -H "Destination: batatinha"
{"id":"batatinha","rev":"1-186fe12b748c40559e8f234d8e566c18"}
$ curl -X GET http://127.0.0.1:5984/contacts/batatinha
{"_id":"batatinha","_rev":"1-186fe12b748c40559e8f234d8e566c18","firstName":"Joao","lastName":"Cerdeira","email":"[email protected]"}
![Page 58: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/58.jpg)
Changing Documents
$ curl -X PUT http://127.0.0.1:5984/contacts/batatinha -d '{"_rev":"1-186fe12b748c40559e8f234d8e566c18","firstName":"Clown","lastName":"Batatinha","email":["[email protected]","[email protected]@rtp.pt"], "phone":"93 1234567"}'
{"ok":true,"id":"batatinha","rev":"2-b7079a6d71179b1571652059355d84c3"}
$ curl -X GET http://127.0.0.1:5984/contacts/batatinha
{"_id":"batatinha","_rev":"2-b7079a6d71179b1571652059355d84c3","firstName":"Clown","lastName":"Batatinha","email":["[email protected]","[email protected]@rtp.pt"], "phone":"93 1234567"}
![Page 59: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/59.jpg)
MVCC
CouchDB never blocks
Append Mode Only
![Page 60: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/60.jpg)
Designing Documents{
"_id":"joaocerdeira", "_rev":"1-186fe12b748c40559e8f234d8e566c18",
“doctype”:”contact”
"firstName":"Joao","lastName":"Cerdeira",“company”:”MULTICERT”
"emails":[{
“type”:”personal”,“email”:"[email protected]“
},{
“type”:”business”,“email”:"[email protected]“
}],“phones”:[
{“type”:”personal”,“phone”:"93 1234567“
},{
“type”:”business”,“phone”:"93 7654321“
}]
}
![Page 61: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/61.jpg)
Designing Documents{
"_id":"joaocerdeira", "_rev":"1-186fe12b748c40559e8f234d8e566c18",
“doctype”:”contact”
"firstName":"Joao","lastName":"Cerdeira",“company”:”MULTICERT”
"emails":[{
“type”:”personal”,“email”:"[email protected]“
},{
“type”:”business”,“email”:"[email protected]“
}],“phones”:[
{“type”:”personal”,“phone”:"93 1234567“
},{
“type”:”business”,“phone”:"93 7654321“
}]
}
![Page 62: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/62.jpg)
Designing Documents{
"_id":"joaocerdeira", "_rev":"1-186fe12b748c40559e8f234d8e566c18",
“doctype”:”contact”
"firstName":"Joao","lastName":"Cerdeira",“company”:”MULTICERT”
"emails":[{
“type”:”personal”,“email”:"[email protected]“
},{
“type”:”business”,“email”:"[email protected]“
}],“phones”:[
{“type”:”personal”,“phone”:"93 1234567“
},{
“type”:”business”,“phone”:"93 7654321“
}]
}
![Page 63: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/63.jpg)
Designing Documents{
"_id":"joaocerdeira", "_rev":"1-186fe12b748c40559e8f234d8e566c18",
“doctype”:”contact”
"firstName":"Joao","lastName":"Cerdeira",“company”:”MULTICERT”
"emails":[{
“type”:”personal”,“email”:"[email protected]“
},{
“type”:”business”,“email”:"[email protected]“
}],“phones”:[
{“type”:”personal”,“phone”:"93 1234567“
},{
“type”:”business”,“phone”:"93 7654321“
}]
}
![Page 64: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/64.jpg)
Futon Web Interface
![Page 65: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/65.jpg)
Views
![Page 66: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/66.jpg)
Quering CouchDB
Queries in JavaScript
Use Map/Reduce for quering
For simple queries Map/Reduce isn't needed
Don't have joins (but you can have similar)
![Page 67: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/67.jpg)
Simple Views
function(doc){emit(doc._id,doc);
}
function(doc){If (doc.type=='vip'){
emit(doc._id,doc);}
}
List All Documents
List All DocumentsOf type 'vip'
![Page 68: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/68.jpg)
Temp Views
$ curl -X POST -H "Content-type: application/json" http://127.0.0.1:5984/contacts/_temp_view -d '{"map":"function(doc){emit(doc._id,doc);}"}'
{"total_rows":2,"offset":0,"rows":[
{"id":"batatinha","key":"batatinha","value":{"_id":"batatinha","_rev":"2-b7079a6d71179b1571652059355d84c3","firstName":"Palhaco","lastName":"Batatinha","email":["[email protected]","[email protected]@rtp.pt"],"phone":"93 1234567"}},{"id":"joaocerdeira","key":"joaocerdeira","value":{"_id":"joaocerdeira","_rev":"1-186fe12b748c40559e8f234d8e566c18","firstName":"Joao","lastName":"Cerdeira","email":"[email protected]","_deleted_conflicts":["2-eec205a9d413992850a6e32678485900"]}}
![Page 69: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/69.jpg)
Normal Views
{"_id" : "_design/example","views" : {
"foo" : {"map":"function(doc){emit(doc._id,doc);}"
}}
}
$ curl -X PUT -H "Content-type: application/json" http://127.0.0.1:5984/contacts/_design/example -d @design_simple1.json
![Page 70: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/70.jpg)
Normal Views
$ curl -X GET http://127.0.0.1:5984/contacts/_design/example/_view/foo {"total_rows":2,"offset":0,"rows":[
{"id":"batatinha","key":"batatinha","value":{"_id":"batatinha","_rev":"2-b7079a6d71179b1571652059355d84c3","firstName":"Palhaco","lastName":"Batatinha","email":["[email protected]","[email protected]@rtp.pt"],"phone":"93 1234567"}},{"id":"joaocerdeira","key":"joaocerdeira","value":{"_id":"joaocerdeira","_rev":"1-186fe12b748c40559e8f234d8e566c18","firstName":"Jo\u00e3o","lastName":"Cerdeira","email":"[email protected]","_deleted_conflicts":["2-eec205a9d413992850a6e32678485900"]}}]}
![Page 71: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/71.jpg)
Map/ReduceGoogle patent from the paper: http:// labs.google .com/papers/mapreduce.html
image source: http://map-reduce.wikispaces.asu.edu/
![Page 72: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/72.jpg)
Map/Reduce Views
{"_id" : "_design/example","views" : {…...................................
"bar" : {"map":"function(doc){emit(doc,1);}","reduce":"function(keys, values, rereduce) {
return sum(values);}"}}}
$ curl -X GET http://127.0.0.1:5984/contacts/_design/example/_view/bar
{"rows":[{"key":null,"value":7}]}
![Page 73: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/73.jpg)
Map/Reduce Views
{"_id" : "_design/example","views" : {…...................................
""aggreg" : { "map":"function(doc){if(doc.country){emit(doc.country,1);}}", "reduce":"function(keys, values, rereduce) {return sum(values);}" }
$ curl -X GET http://127.0.0.1:5984/contacts/_design/example/_view/aggreg?group=true {"rows":[{"key":"England","value":1},{"key":"Portugal","value":2},{"key":"US","value":2}]}
![Page 74: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/74.jpg)
Replication
![Page 75: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/75.jpg)
Write
Read
![Page 76: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/76.jpg)
Write
ReadRead
![Page 77: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/77.jpg)
Write
ReadRead
Read
![Page 78: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/78.jpg)
One Time Replication
$ curl -H "Content-type: application/json -X POST http://127.0.0.1:5984/_replicate -d '{"source":"contacts","target":"contacts-replica"}'
{"ok":true,"session_id":"00872a440fdda973d6a9a18f2f571bb8","source_last_seq":19,"history": [{"session_id":"00872a440fdda973d6a9a18f2f571bb8","start_time":"Tue, 05 Jul 2011 23:03:32 GMT","end_time":"Tue, 05 Jul 2011 23:03:32 GMT","start_last_seq":0,"end_last_seq":19,"recorded_seq":19,"missing_checked":0,"missing_found":8,"docs_read":12,"docs_written":12,"doc_write_failures":0}]}
![Page 79: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/79.jpg)
Write Write
![Page 80: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/80.jpg)
Continuous Replication
$ curl -vX POST http://127.0.0.1:5984/_replicate-d '{
"source":"http://127.0.0.1:5984/contacts","target":"http://127.0.0.1:5984/contacts-replica","continuous":true
}'
![Page 81: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/81.jpg)
Write Write
Read Write
White WriteRead
![Page 82: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/82.jpg)
Load BalancingCaching
It's HTTP. So use the tools you know-> NGINX-> Squid-> Apache mod_proxy-> …....
![Page 83: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/83.jpg)
Library
Conflict Resolution
http://thetowersofjacksonville.com/photogallery/photo12411/real.htmhttp://thetowersofjacksonville.com/photogallery/photo12411/real.htmhttp://thetowersofjacksonville.com/photogallery/photo12411/real.htmhttp://thetowersofjacksonville.com/photogallery/photo12411/real.htmhttp://thetowersofjacksonville.com/photogallery/photo12411/real.html
![Page 84: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/84.jpg)
![Page 85: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/85.jpg)
![Page 86: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/86.jpg)
![Page 87: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/87.jpg)
![Page 88: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/88.jpg)
Conflicts Resolution
function(doc) {
if(doc._conflicts) {emit(doc._conflicts, null);}
}
{"total_rows":1,"offset":0,"rows":[{"id":"identifier","key":["2-7c971bb974251ae8541b8fe045964219"],"value":null}]}
$ curl -X DELETE $HOST/db-replica/identifier?rev=2-de0ea16f8621cbac506d23a0fbbde08a
{"ok":true,"id":"identifier","rev":"3-bfe83a296b0445c4d526ef35ef62ac14"}
$ curl -X PUT $HOST/db-replica/identifier-d '{"count":3,"_rev":"2-7c971bb974251ae8541b8fe045964219"}'
{"ok":true,"id":"identifier","rev":"3-5d0319b075a21b095719bc561def7122"}
![Page 89: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/89.jpg)
Library
http://thetowersofjacksonville.com/photogallery/photo12411/real.htm
![Page 90: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/90.jpg)
ClientsJavaScript : Jquery CouchDB Library.Net : RelaxJava : CouchDB4JPerl : CouchDB::Client Net::CouchDbRuby : CouchRestPython : couchdb-pythonScala : scouchdbAnd so much more ...
![Page 91: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/91.jpg)
CouchDBIn
Mobile
http://www.digitaljournal.com/article/261153
![Page 92: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/92.jpg)
Mobile PlatformsSupported
![Page 93: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/93.jpg)
Simply Works
![Page 94: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/94.jpg)
PhoneGAP LawnChair
![Page 95: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/95.jpg)
Own Your Data
I like services like google but what aboutmy privacy ?!
I think CouchDB is the way to own my data
![Page 96: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/96.jpg)
http://thetowersofjacksonville.com/photogallery/photo12411/real.htm
Partition with Cluster
![Page 97: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/97.jpg)
Solutions
![Page 98: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/98.jpg)
![Page 99: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/99.jpg)
“CouchDB is built of the Web to the Web”
– Jacob Kaplan-Moss
![Page 100: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/100.jpg)
We need a MindSetChange
Stop seing all the data in the
world as relational data
![Page 101: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/101.jpg)
Don't trust me . . . or othersTry it !
![Page 102: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/102.jpg)
And the Future…
Probably will be polyglot
Using RDBMS and more than one NoSQL
Database per solution
![Page 103: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/103.jpg)
Success Stories
![Page 104: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/104.jpg)
![Page 105: NoSQL and CouchDB](https://reader033.vdocuments.site/reader033/viewer/2022042521/545409e9af795919308b5536/html5/thumbnails/105.jpg)