SlideShare a Scribd company logo
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

More Related Content

What's hot

Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
Stephen Colebourne
 
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
Tae Young Lee
 
Asp.net caching
Asp.net cachingAsp.net caching
Asp.net caching
Mindfire Solutions
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
Duoyi Wu
 
Quick Guide with Linux Command Line
Quick Guide with Linux Command LineQuick Guide with Linux Command Line
Quick Guide with Linux Command Line
Anuchit Chalothorn
 
Shell Scripting Tutorial | Edureka
Shell Scripting Tutorial | EdurekaShell Scripting Tutorial | Edureka
Shell Scripting Tutorial | Edureka
Edureka!
 
Models for hierarchical data
Models for hierarchical dataModels for hierarchical data
Models for hierarchical data
Karwin Software Solutions LLC
 
MEAN stack
MEAN stackMEAN stack
MEAN stack
Iryney Baran
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Edureka!
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?
Sam Thomas
 
Vi Cheat Sheet v 1 00
Vi Cheat Sheet v 1 00Vi Cheat Sheet v 1 00
Vi Cheat Sheet v 1 00
Nicole Cordes
 
Smart pointers
Smart pointersSmart pointers
Smart pointers
Vishal Mahajan
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
Amit Ghosh
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
Nisa Soomro
 
PHP
PHPPHP
Trends and future of C++: Evolving a systems language for performance - by Bj...
Trends and future of C++: Evolving a systems language for performance - by Bj...Trends and future of C++: Evolving a systems language for performance - by Bj...
Trends and future of C++: Evolving a systems language for performance - by Bj...
devstonez
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
FYBSC IT Web Programming Unit V  Advanced PHP and MySQLFYBSC IT Web Programming Unit V  Advanced PHP and MySQL
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
Arti Parab Academics
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local Storage
Lior Zamir
 
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) [Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
Johnny Sung
 

What's hot (20)

Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
 
Asp.net caching
Asp.net cachingAsp.net caching
Asp.net caching
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
 
Quick Guide with Linux Command Line
Quick Guide with Linux Command LineQuick Guide with Linux Command Line
Quick Guide with Linux Command Line
 
Shell Scripting Tutorial | Edureka
Shell Scripting Tutorial | EdurekaShell Scripting Tutorial | Edureka
Shell Scripting Tutorial | Edureka
 
Models for hierarchical data
Models for hierarchical dataModels for hierarchical data
Models for hierarchical data
 
MEAN stack
MEAN stackMEAN stack
MEAN stack
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?
 
Vi Cheat Sheet v 1 00
Vi Cheat Sheet v 1 00Vi Cheat Sheet v 1 00
Vi Cheat Sheet v 1 00
 
Smart pointers
Smart pointersSmart pointers
Smart pointers
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
PHP
PHPPHP
PHP
 
Trends and future of C++: Evolving a systems language for performance - by Bj...
Trends and future of C++: Evolving a systems language for performance - by Bj...Trends and future of C++: Evolving a systems language for performance - by Bj...
Trends and future of C++: Evolving a systems language for performance - by Bj...
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
FYBSC IT Web Programming Unit V  Advanced PHP and MySQLFYBSC IT Web Programming Unit V  Advanced PHP and MySQL
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local Storage
 
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) [Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
 

Viewers also liked

CouchDB Map/Reduce
CouchDB Map/ReduceCouchDB Map/Reduce
CouchDB Map/Reduce
Oliver Kurowski
 
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
MongoDB
 
CouchDB Vs MongoDB
CouchDB Vs MongoDBCouchDB Vs MongoDB
CouchDB Vs MongoDB
Gabriele Lana
 
Apresentação cassandra
Apresentação cassandraApresentação cassandra
Apresentação cassandraRichiely Paiva
 
Couchbase Performance Benchmarking
Couchbase Performance BenchmarkingCouchbase Performance Benchmarking
Couchbase Performance Benchmarking
Renat Khasanshyn
 
CouchDB
CouchDBCouchDB
MapReduce in Simple Terms
MapReduce in Simple TermsMapReduce in Simple Terms
MapReduce in Simple Terms
Saliya Ekanayake
 
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
SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
SlideShare
 

Viewers also liked (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
 

Similar to Couchdb List and Show Introduction

Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DB
Mihail Mateev
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
Nicola Iarocci
 
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
Ramakrishna Reddy Bijjam
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responses
darrelmiller71
 
Introduction to CouchDB - LA Hacker News
Introduction to CouchDB - LA Hacker NewsIntroduction to CouchDB - LA Hacker News
Introduction to CouchDB - LA Hacker News
Michael 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 management
Binary Studio
 
MongoDB
MongoDBMongoDB
MongoDB
Steve Klabnik
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
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 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 Bavaria
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Algiers Tech Meetup
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
Henrik Ingo
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
Bradley 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 Perspective
Seh 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 intro
christkv
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab
Fabio Fumarola
 

Similar to 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
 

Recently uploaded

Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdfBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
daothibichhang1
 
Recruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media MasterclassRecruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media Masterclass
LuanWise
 
BeMetals Investor Presentation_June 1, 2024.pdf
BeMetals Investor Presentation_June 1, 2024.pdfBeMetals Investor Presentation_June 1, 2024.pdf
BeMetals Investor Presentation_June 1, 2024.pdf
DerekIwanaka1
 
3.0 Project 2_ Developing My Brand Identity Kit.pptx
3.0 Project 2_ Developing My Brand Identity Kit.pptx3.0 Project 2_ Developing My Brand Identity Kit.pptx
3.0 Project 2_ Developing My Brand Identity Kit.pptx
tanyjahb
 
-- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month ---- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month --
NZSG
 
amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05
marketing317746
 
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Lviv Startup Club
 
Authentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto RicoAuthentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto Rico
Corey Perlman, Social Media Speaker and Consultant
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
agatadrynko
 
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBdCree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
creerey
 
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Lviv Startup Club
 
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
bosssp10
 
Premium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern BusinessesPremium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern Businesses
SynapseIndia
 
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challengesEvent Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Holger Mueller
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
FelixPerez547899
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
dylandmeas
 
Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024
Kirill Klimov
 
The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...
balatucanapplelovely
 
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
SOFTTECHHUB
 
Set off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptxSet off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptx
HARSHITHV26
 

Recently uploaded (20)

Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdfBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
 
Recruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media MasterclassRecruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media Masterclass
 
BeMetals Investor Presentation_June 1, 2024.pdf
BeMetals Investor Presentation_June 1, 2024.pdfBeMetals Investor Presentation_June 1, 2024.pdf
BeMetals Investor Presentation_June 1, 2024.pdf
 
3.0 Project 2_ Developing My Brand Identity Kit.pptx
3.0 Project 2_ Developing My Brand Identity Kit.pptx3.0 Project 2_ Developing My Brand Identity Kit.pptx
3.0 Project 2_ Developing My Brand Identity Kit.pptx
 
-- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month ---- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month --
 
amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05
 
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
Helen Lubchak: Тренди в управлінні проєктами та miltech (UA)
 
Authentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto RicoAuthentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto Rico
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
 
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBdCree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
 
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
 
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
 
Premium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern BusinessesPremium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern Businesses
 
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challengesEvent Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
 
Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024
 
The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...
 
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
Hamster Kombat' Telegram Game Surpasses 100 Million Players—Token Release Sch...
 
Set off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptxSet off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptx
 

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