SlideShare uma empresa Scribd logo
1 de 26
COUCHDB

<- Watch the car   Oliver Kurowski, @okurow
Who am I
 Oliver Kurowski
 Degree in Computer Science Beuth School of applied Sciences Berlin


 First Computer: Apple II 1983
 Since 2003: kw automotive GmbH


 Write articles in Magazines
 2012: Book „CouchDB mit PHP“ (www.CouchDBmitPHP.de)


 Twitter: @okurow
 Mail: oliver@thinkcouchdb.com




                                      Oliver Kurowski, @okurow
TRANSFORMATIONS

                  Oliver Kurowski, @okurow
Transformation Functions
Documents are JSON objects
Results of views are also JSON objects

CouchDB can transfrom those JSON Objects on server side.

Shows:           Transformation for documents
Lists:           Transformation for views

Shows and lists are performed during request, results are not stored (like views).




                                         Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I
Data document (JSON):        Show function in a design doc:
 {                           “shows“: {
 “_id“: “1“,                  “toHTML“:“function(doc,req) {
 “make“: “Audi“,                 var outS=‘‘;
 “model“: “A3“,                  outS=‘<b>‘+doc.maker+‘ ‘+doc.model+‘</b><br>`;
 “year“: 2000,                   outS+=‘Year of Prod.: ‘+doc.year+‘<br>‘;
 “price“: 5.400                  outS+=‘Price: ‘+doc.price;
 }                              return outS; }“
                              }



Result of _show/toHTML/1 :
 Audi A3
 Year of Prod.: 2000
 Price: 5.400




                                   Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {
     var comments=0;
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
     outS+= doc.body + ‘<br>`;
     if (doc.comments && doc.comments.length>0) {
       outS+= ‘comments:<br>`;
       for (var curComment in doc.comments) {
        outS+=doc.comments[curComment].name+‘:<br>`;
        outS+=doc.comments[curComment].text+‘<br>`;
      }
   }
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {
     var comments=0;
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
     outS+= doc.body + ‘<br>`;
     if (doc.comments && doc.comments.length>0) {
       outS+= ‘comments:<br>`;
       for (var curComment in doc.comments) {
        outS+=doc.comments[curComment].name+‘:<br>`;
        outS+=doc.comments[curComment].text+‘<br>`;
      }
   }
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {
     var comments=0;
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
     outS+= doc.body + ‘<br>`;
     if (doc.comments && doc.comments.length>0) {
       outS+= ‘comments:<br>`;
       for (var curComment in doc.comments) {
        outS+=doc.comments[curComment].name+‘:<br>`;
        outS+=doc.comments[curComment].text+‘<br>`;
      }
   }
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data.“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {                                              Result of _show/headline/1 :
     var comments=0;                                                             CouchDB is great (2 comments)
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
     outS+= doc.body + ‘<br>`;
     if (doc.comments && doc.comments.length>0) {
       outS+= ‘<hr>Comments:<br>`;
       for (var curComment in doc.comments) {
        outS+=doc.comments[curComment].name+‘:<br>`;
        outS+=doc.comments[curComment].text+‘<br>`;
      }
   }
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data.“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {                                              Result of _show/headline/1 :
     var comments=0;                                                             CouchDB is great (2 comments)
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
                                                                               Result of _show/detail/1 :
     outS+= doc.body + ‘<br>`;                                                   CouchDB is great
     if (doc.comments && doc.comments.length>0) {                                CouchDb is a great database for schemeless data.
       outS+= ‘<hr>Comments:<br>`;
       for (var curComment in doc.comments) {                                    Comments:
        outS+=doc.comments[curComment].name+‘:<br>`;                             John:
        outS+=doc.comments[curComment].text+‘<br>`;                              Yes, it really is
      }                                                                          Jane:
   }                                                                             What about couchbase?
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
The Request Object
Shows and lists can access the Request Object containing:
(the most interesting)

Info:           Informations about the Database
Id:             called document ID (null, if not given)
requested
_path:          The request in parts (divided by /) as Array
headers:        Header, sent from the client
userCTX:        Information about the user, usefull for access limitations!
query:          Parameters of the call

The field req.query allows the use of own parameters that can be used in a
show/list function.
F.e: _show/toHTML/1?showPrice=true

handled in the show function:   if(req.query.showPrice==true) { ….}

                                         Oliver Kurowski, @okurow
Shows:Talking Parrots
Data documents :                      Design document :
{                                     {
    “_id“: “lora“,                         “_id“: “_design/parrot“,
    “name“: “Lora LoL“,                    “shows{
    “owner“: “Emily“,                       "introduce": "function(doc,req) {
    “color“: [“red“ , “#ff0000“ ] ,            var outS='';
    “languages“: [ “english“ ]                 if(doc) {     // doc with id in database found
}                                                outS+='<font color='+doc.color[1]+'>'+doc.name
                                                       +' belongs to '+doc.owner+'</font>';
{                                                if(req.query.say) {
    “_id“: “polly“,                                if(doc.languages) {
    “name“: “Polly Poll“,                            outS+=' and says: '+req.query.say;
    “owner“: “Ernest“,                             }else{
    “color“: [“blue“ , “#0000ff“ ],                  outS+='tweet';
    “languages“: [ “english“ ]                     }
}                                                }
                                               } else { // no doc found
                                                 if(req.path[5]!=undefined) { // no id given
{                                                  outS+='I dont know '+req.path[5];
    “_id“: “agnus“,                              }else{
    “name“: “Agnus Angry“,                          outS+='which parrot?';
    “owner“: “Ernest“,                           }
    “color“: [“grey“ , “#cococo“ ]            }
}                                             return outS; }“
                                          }
                                      }



                                                  Oliver Kurowski, @okurow
Shows: Talking Parrots
http://localhost:5984/parrots/_design/parrot/_show/introduce/
->which parrot?

http://localhost:5984/parrots/_design/parrot/_show/introduce/polly
->Polly Poll belongs to Ernest

http://localhost:5984/parrots/_design/parrot/_show/introduce/pollx
->I dont know pollx

http://localhost:5984/parrots/_design/parrot/_show/introduce/lora?say=Hello
->Lora Loll belongs to Emily and says: Hello

http://localhost:5984/parrots/_design/parrot/_show/introduce/agnus?say=Hello
->Agnus Angry belongs to Ernest tweet




                                       Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I
Result of a View byPrice:                          A simple list function:
{"total_rows":5,"offset":0,                         “lists“: {
"rows":[                                              “asLI “:“function(head,req) {
{"id":"1","key":5.400,"value":“Audi-A3-                 start({'code':200,'headers':{'Content-Type':'text/html'}});
2000“}, {"id":"2","key":9.000,"value":“VW-Golf-         while(row=getRow()) {
2008“}, {"id":"3","key":12.000,"value":“VW-Polo-          send(‘<li>‘+row.value+‘ :‘ +row.key+‘</li>‘);
2010“}, {"id":"4","key":15.000,"value":“VW-Golf-        }
2009“}, {"id":"5","key":16.000,"value":“Audi-A4-      }“
2009“} ]}                                           }


result from _list/asLi/byPrice :
 •   Audi-A3-2000 : 5.400
 •   VW-Golf-2008 : 9.000
 •   VW-Polo-2010 : 12.000
 •   VW-Golf-2009 : 15.000
 •   Audi-A4-2009 : 16.000


- All arguments from a view can also be used in a list call
(startkey, endkey, skip, limit etc)

- Like Shows, you have access to the request Object with all ist possibilities.
                                                              Oliver Kurowski, @okurow
List:Transform view results II
Different headers can be sent
“lists“: {
  “asXML “:“function(head,req) {
    start({'code':200,'headers':{'Content-Type':'application/xml'}});
    var xmlS=‘<cars>‘;
    while(row=getRow()) {
      xmlS+=‘<car id=‘ + row.id + ‘>‘+row.value+‘ :‘ +row.key+‘</car>‘);
    }
    xmlS+=‘</cars>‘;
   return xmlS;
  }“
}


result from _list/asXML/byPrice :
<cars>
<car id=‘1‘>Audi-A3-2000 : 5.400</car>
<car id=‘2‘>VW-Golf-2008 : 9.000</car>
<car id=‘3‘ >VW-Polo-2010 : 12.000</car>
<car id=‘4‘>VW-Golf-2009 : 15.000</car>
<car id=‘5‘>Audi-A4-2009 : 16.000</car>
</cars>




                                                                       Oliver Kurowski, @okurow
http://apache.couchdb.org

Irc: #couchdb




Q (&A?)

                            Oliver Kurowski, @okurow

Mais conteúdo relacionado

Mais procurados

Python: The Complete Reference by Martin C. Brown
Python: The Complete Reference by Martin C. BrownPython: The Complete Reference by Martin C. Brown
Python: The Complete Reference by Martin C. Browneavdsavv
 
분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB]
분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB]분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB]
분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB]MongoDB
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation FrameworkMongoDB
 
File Access Permission
File Access PermissionFile Access Permission
File Access PermissionBIT DURG
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB FundamentalsMongoDB
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query OptimizationMongoDB
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PGPgDay.Seoul
 
Apache Arrow and Pandas UDF on Apache Spark
Apache Arrow and Pandas UDF on Apache SparkApache Arrow and Pandas UDF on Apache Spark
Apache Arrow and Pandas UDF on Apache SparkTakuya UESHIN
 
MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...
MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...
MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...ScyllaDB
 
Hive and Apache Tez: Benchmarked at Yahoo! Scale
Hive and Apache Tez: Benchmarked at Yahoo! ScaleHive and Apache Tez: Benchmarked at Yahoo! Scale
Hive and Apache Tez: Benchmarked at Yahoo! ScaleDataWorks Summit
 
07 - Hadoop. Решение задач с помощью MapReduce
07 - Hadoop. Решение задач с помощью MapReduce07 - Hadoop. Решение задач с помощью MapReduce
07 - Hadoop. Решение задач с помощью MapReduceRoman Brovko
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]MongoDB
 
Building Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and HydraBuilding Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and HydraMarkus Lanthaler
 
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Ahmed El-Arabawy
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshellFabien Gandon
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perldeepfountainconsulting
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseMike Dirolf
 
Relational RDBMS : MySQL, PostgreSQL and SQL SERVER
Relational RDBMS  : MySQL, PostgreSQL and SQL SERVERRelational RDBMS  : MySQL, PostgreSQL and SQL SERVER
Relational RDBMS : MySQL, PostgreSQL and SQL SERVERDalila Chouaya
 

Mais procurados (20)

Python: The Complete Reference by Martin C. Brown
Python: The Complete Reference by Martin C. BrownPython: The Complete Reference by Martin C. Brown
Python: The Complete Reference by Martin C. Brown
 
분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB]
분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB]분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB]
분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB]
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 
File Access Permission
File Access PermissionFile Access Permission
File Access Permission
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
 
Mongo db 최범균
Mongo db 최범균Mongo db 최범균
Mongo db 최범균
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query Optimization
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
 
Apache Arrow and Pandas UDF on Apache Spark
Apache Arrow and Pandas UDF on Apache SparkApache Arrow and Pandas UDF on Apache Spark
Apache Arrow and Pandas UDF on Apache Spark
 
MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...
MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...
MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...
 
Hive and Apache Tez: Benchmarked at Yahoo! Scale
Hive and Apache Tez: Benchmarked at Yahoo! ScaleHive and Apache Tez: Benchmarked at Yahoo! Scale
Hive and Apache Tez: Benchmarked at Yahoo! Scale
 
07 - Hadoop. Решение задач с помощью MapReduce
07 - Hadoop. Решение задач с помощью MapReduce07 - Hadoop. Решение задач с помощью MapReduce
07 - Hadoop. Решение задач с помощью MapReduce
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
 
Building Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and HydraBuilding Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and Hydra
 
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshell
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
 
Relational RDBMS : MySQL, PostgreSQL and SQL SERVER
Relational RDBMS  : MySQL, PostgreSQL and SQL SERVERRelational RDBMS  : MySQL, PostgreSQL and SQL SERVER
Relational RDBMS : MySQL, PostgreSQL and SQL SERVER
 

Destaque

MongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDB
MongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDBMongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDB
MongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDBMongoDB
 
Apresentação cassandra
Apresentação cassandraApresentação cassandra
Apresentação cassandraRichiely Paiva
 
Couchbase Performance Benchmarking
Couchbase Performance BenchmarkingCouchbase Performance Benchmarking
Couchbase Performance BenchmarkingRenat Khasanshyn
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

Destaque (9)

CouchDB Map/Reduce
CouchDB Map/ReduceCouchDB Map/Reduce
CouchDB Map/Reduce
 
MongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDB
MongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDBMongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDB
MongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDB
 
CouchDB Vs MongoDB
CouchDB Vs MongoDBCouchDB Vs MongoDB
CouchDB Vs MongoDB
 
Apresentação cassandra
Apresentação cassandraApresentação cassandra
Apresentação cassandra
 
Couchbase Performance Benchmarking
Couchbase Performance BenchmarkingCouchbase Performance Benchmarking
Couchbase Performance Benchmarking
 
CouchDB
CouchDBCouchDB
CouchDB
 
MapReduce in Simple Terms
MapReduce in Simple TermsMapReduce in Simple Terms
MapReduce in Simple Terms
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Semelhante a Couchdb List and Show Introduction

Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DBMihail Mateev
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™Nicola Iarocci
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responsesdarrelmiller71
 
Introduction to CouchDB - LA Hacker News
Introduction to CouchDB - LA Hacker NewsIntroduction to CouchDB - LA Hacker News
Introduction to CouchDB - LA Hacker NewsMichael Parker
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?Trisha Gee
 
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...MongoDB
 
Academy PRO: Elasticsearch. Data management
Academy PRO: Elasticsearch. Data managementAcademy PRO: Elasticsearch. Data management
Academy PRO: Elasticsearch. Data managementBinary Studio
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
MongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB AppHenrik Ingo
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Comsysto Reply GmbH
 
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveTearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveSeh Hui Leong
 
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...MongoDB
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases labFabio Fumarola
 

Semelhante a Couchdb List and Show Introduction (20)

Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DB
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
 
CSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptxCSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responses
 
Introduction to CouchDB - LA Hacker News
Introduction to CouchDB - LA Hacker NewsIntroduction to CouchDB - LA Hacker News
Introduction to CouchDB - LA Hacker News
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
 
Academy PRO: Elasticsearch. Data management
Academy PRO: Elasticsearch. Data managementAcademy PRO: Elasticsearch. Data management
Academy PRO: Elasticsearch. Data management
 
MongoDB
MongoDBMongoDB
MongoDB
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
MongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in Bavaria
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
 
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveTearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
 
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab
 

Último

Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...amitlee9823
 
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyThe Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyEthan lee
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...lizamodels9
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.Aaiza Hassan
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...Any kyc Account
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Lviv Startup Club
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsMichael W. Hawkins
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...anilsa9823
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMRavindra Nath Shukla
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Roland Driesen
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxpriyanshujha201
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒anilsa9823
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfAmzadHosen3
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxWorkforce Group
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...amitlee9823
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Serviceritikaroy0888
 

Último (20)

Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyThe Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael Hawkins
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
 
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdf
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Service
 

Couchdb List and Show Introduction

  • 1. COUCHDB <- Watch the car Oliver Kurowski, @okurow
  • 2. Who am I  Oliver Kurowski  Degree in Computer Science Beuth School of applied Sciences Berlin  First Computer: Apple II 1983  Since 2003: kw automotive GmbH  Write articles in Magazines  2012: Book „CouchDB mit PHP“ (www.CouchDBmitPHP.de)  Twitter: @okurow  Mail: oliver@thinkcouchdb.com Oliver Kurowski, @okurow
  • 3. TRANSFORMATIONS Oliver Kurowski, @okurow
  • 4. Transformation Functions Documents are JSON objects Results of views are also JSON objects CouchDB can transfrom those JSON Objects on server side. Shows: Transformation for documents Lists: Transformation for views Shows and lists are performed during request, results are not stored (like views). Oliver Kurowski, @okurow
  • 5. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 6. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 7. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 8. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 9. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 10. Shows:Transform Documents I Data document (JSON): Show function in a design doc: { “shows“: { “_id“: “1“, “toHTML“:“function(doc,req) { “make“: “Audi“, var outS=‘‘; “model“: “A3“, outS=‘<b>‘+doc.maker+‘ ‘+doc.model+‘</b><br>`; “year“: 2000, outS+=‘Year of Prod.: ‘+doc.year+‘<br>‘; “price“: 5.400 outS+=‘Price: ‘+doc.price; } return outS; }“ } Result of _show/toHTML/1 : Audi A3 Year of Prod.: 2000 Price: 5.400 Oliver Kurowski, @okurow
  • 11. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { var comments=0; if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; outS+= doc.body + ‘<br>`; if (doc.comments && doc.comments.length>0) { outS+= ‘comments:<br>`; for (var curComment in doc.comments) { outS+=doc.comments[curComment].name+‘:<br>`; outS+=doc.comments[curComment].text+‘<br>`; } } return outS; }“ } Oliver Kurowski, @okurow
  • 12. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { var comments=0; if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; outS+= doc.body + ‘<br>`; if (doc.comments && doc.comments.length>0) { outS+= ‘comments:<br>`; for (var curComment in doc.comments) { outS+=doc.comments[curComment].name+‘:<br>`; outS+=doc.comments[curComment].text+‘<br>`; } } return outS; }“ } Oliver Kurowski, @okurow
  • 13. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { var comments=0; if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; outS+= doc.body + ‘<br>`; if (doc.comments && doc.comments.length>0) { outS+= ‘comments:<br>`; for (var curComment in doc.comments) { outS+=doc.comments[curComment].name+‘:<br>`; outS+=doc.comments[curComment].text+‘<br>`; } } return outS; }“ } Oliver Kurowski, @okurow
  • 14. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data.“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { Result of _show/headline/1 : var comments=0; CouchDB is great (2 comments) if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; outS+= doc.body + ‘<br>`; if (doc.comments && doc.comments.length>0) { outS+= ‘<hr>Comments:<br>`; for (var curComment in doc.comments) { outS+=doc.comments[curComment].name+‘:<br>`; outS+=doc.comments[curComment].text+‘<br>`; } } return outS; }“ } Oliver Kurowski, @okurow
  • 15. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data.“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { Result of _show/headline/1 : var comments=0; CouchDB is great (2 comments) if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; Result of _show/detail/1 : outS+= doc.body + ‘<br>`; CouchDB is great if (doc.comments && doc.comments.length>0) { CouchDb is a great database for schemeless data. outS+= ‘<hr>Comments:<br>`; for (var curComment in doc.comments) { Comments: outS+=doc.comments[curComment].name+‘:<br>`; John: outS+=doc.comments[curComment].text+‘<br>`; Yes, it really is } Jane: } What about couchbase? return outS; }“ } Oliver Kurowski, @okurow
  • 16. The Request Object Shows and lists can access the Request Object containing: (the most interesting) Info: Informations about the Database Id: called document ID (null, if not given) requested _path: The request in parts (divided by /) as Array headers: Header, sent from the client userCTX: Information about the user, usefull for access limitations! query: Parameters of the call The field req.query allows the use of own parameters that can be used in a show/list function. F.e: _show/toHTML/1?showPrice=true handled in the show function: if(req.query.showPrice==true) { ….} Oliver Kurowski, @okurow
  • 17. Shows:Talking Parrots Data documents : Design document : { { “_id“: “lora“, “_id“: “_design/parrot“, “name“: “Lora LoL“, “shows{ “owner“: “Emily“, "introduce": "function(doc,req) { “color“: [“red“ , “#ff0000“ ] , var outS=''; “languages“: [ “english“ ] if(doc) { // doc with id in database found } outS+='<font color='+doc.color[1]+'>'+doc.name +' belongs to '+doc.owner+'</font>'; { if(req.query.say) { “_id“: “polly“, if(doc.languages) { “name“: “Polly Poll“, outS+=' and says: '+req.query.say; “owner“: “Ernest“, }else{ “color“: [“blue“ , “#0000ff“ ], outS+='tweet'; “languages“: [ “english“ ] } } } } else { // no doc found if(req.path[5]!=undefined) { // no id given { outS+='I dont know '+req.path[5]; “_id“: “agnus“, }else{ “name“: “Agnus Angry“, outS+='which parrot?'; “owner“: “Ernest“, } “color“: [“grey“ , “#cococo“ ] } } return outS; }“ } } Oliver Kurowski, @okurow
  • 18. Shows: Talking Parrots http://localhost:5984/parrots/_design/parrot/_show/introduce/ ->which parrot? http://localhost:5984/parrots/_design/parrot/_show/introduce/polly ->Polly Poll belongs to Ernest http://localhost:5984/parrots/_design/parrot/_show/introduce/pollx ->I dont know pollx http://localhost:5984/parrots/_design/parrot/_show/introduce/lora?say=Hello ->Lora Loll belongs to Emily and says: Hello http://localhost:5984/parrots/_design/parrot/_show/introduce/agnus?say=Hello ->Agnus Angry belongs to Ernest tweet Oliver Kurowski, @okurow
  • 19. List:Transform view results I Oliver Kurowski, @okurow
  • 20. List:Transform view results I Oliver Kurowski, @okurow
  • 21. List:Transform view results I Oliver Kurowski, @okurow
  • 22. List:Transform view results I Oliver Kurowski, @okurow
  • 23. List:Transform view results I Oliver Kurowski, @okurow
  • 24. List:Transform view results I Result of a View byPrice: A simple list function: {"total_rows":5,"offset":0, “lists“: { "rows":[ “asLI “:“function(head,req) { {"id":"1","key":5.400,"value":“Audi-A3- start({'code':200,'headers':{'Content-Type':'text/html'}}); 2000“}, {"id":"2","key":9.000,"value":“VW-Golf- while(row=getRow()) { 2008“}, {"id":"3","key":12.000,"value":“VW-Polo- send(‘<li>‘+row.value+‘ :‘ +row.key+‘</li>‘); 2010“}, {"id":"4","key":15.000,"value":“VW-Golf- } 2009“}, {"id":"5","key":16.000,"value":“Audi-A4- }“ 2009“} ]} } result from _list/asLi/byPrice : • Audi-A3-2000 : 5.400 • VW-Golf-2008 : 9.000 • VW-Polo-2010 : 12.000 • VW-Golf-2009 : 15.000 • Audi-A4-2009 : 16.000 - All arguments from a view can also be used in a list call (startkey, endkey, skip, limit etc) - Like Shows, you have access to the request Object with all ist possibilities. Oliver Kurowski, @okurow
  • 25. List:Transform view results II Different headers can be sent “lists“: { “asXML “:“function(head,req) { start({'code':200,'headers':{'Content-Type':'application/xml'}}); var xmlS=‘<cars>‘; while(row=getRow()) { xmlS+=‘<car id=‘ + row.id + ‘>‘+row.value+‘ :‘ +row.key+‘</car>‘); } xmlS+=‘</cars>‘; return xmlS; }“ } result from _list/asXML/byPrice : <cars> <car id=‘1‘>Audi-A3-2000 : 5.400</car> <car id=‘2‘>VW-Golf-2008 : 9.000</car> <car id=‘3‘ >VW-Polo-2010 : 12.000</car> <car id=‘4‘>VW-Golf-2009 : 15.000</car> <car id=‘5‘>Audi-A4-2009 : 16.000</car> </cars> Oliver Kurowski, @okurow