SlideShare a Scribd company logo
1 of 19
Download to read offline
Introduction to CouchDB

Jon Allen (JJ) – jj@opusvl.com
     YAPC::Europe 2010


     Introduction to CouchDB
     Open Source Business Systems
   www.opusvl.com
What is CouchDB?
                           

•  Document Oriented Database




               Introduction to CouchDB
               Open Source Business Systems
   www.opusvl.com
What is CouchDB?
                              

•  Document Oriented Database
  –  No schema
     •  Stores "documents" (i.e. data structures)
  –  No SQL
     •  Uses "MapReduce" queries written in JavaScript




                   Introduction to CouchDB
                   Open Source Business Systems
     www.opusvl.com
What is CouchDB?
                               

•  Document Oriented Database
   –  No schema
      •  Stores "documents" (i.e. data structures)
   –  No SQL
      •  Uses "MapReduce" queries written in JavaScript


•  Written in Erlang
•  REST API
•  Replication, scalability

                    Introduction to CouchDB
                    Open Source Business Systems
     www.opusvl.com
Why use CouchDB?
                               

•    Store complex data structures (JSON)
•    Store variable data structures (no schema)
•    De-normalised / self contained
•    Add attachments to documents
•    Scalable and fault tolerant

•  Better fit for certain problem domains
     –  Messaging
     –  CMS

                     Introduction to CouchDB
                     Open Source Business Systems
   www.opusvl.com
Using CouchDB from Perl
                               

•  HTTP REST API
•  No DBI, DBD, DBIx::Class etc

•  CPAN modules
  –  CouchDB::Client
  –  AnyEvent::CouchDB




                Introduction to CouchDB
                Open Source Business Systems
   www.opusvl.com
Creating a database
                             
use CouchDB::Client;
use Try::Tiny;

my $client = CouchDB::Client->new(
    uri => 'http://localhost:5984'
);

my $db = $client->newDB('jj_test');           # lower case!

try {
    $db->create;
} catch {
    die "Could not create DB";
};

              Introduction to CouchDB
              Open Source Business Systems
      www.opusvl.com
Inserting a document
                             
my $client = CouchDB::Client->new();
my $db     = $client->newDB('jj_test');

my $doc    = $db->newDoc('docid', undef, {
    type => 'message',
    text => 'Hello, World',
    to   => ['JJ', 'Barbie', 'Brian'],
});

try {
    $doc->create;
} catch {
    die "Could not create document";
};

              Introduction to CouchDB
              Open Source Business Systems
   www.opusvl.com
Inserting a document
                             
my $client = CouchDB::Client->new();
my $db     = $client->newDB('jj_test');

my $doc    = $db->newDoc('docid', undef, {
    type => 'message',
    text => 'Hello, World',
    to   => ['JJ', 'Barbie', 'Brian'],
});

try {                   Document ID,          Revision ID
    $doc->create;      must be unique
} catch {
    die "Could not create document";
};

              Introduction to CouchDB
              Open Source Business Systems
     www.opusvl.com
CouchDB GUI
           




Introduction to CouchDB
Open Source Business Systems
   www.opusvl.com
Querying documents
                              

  All Documents
                                                  Map function




                                                   Key, Value
Key, Value                                         Key, Value
                        Query by Key
Key, Value
                                                   Key, Value

                                                   Key, Value


                  Introduction to CouchDB
                  Open Source Business Systems
     www.opusvl.com
Views
                                  

•  A view is a JavaScript function 
   –  Like a stored procedure in SQL
•  Map function is executed on every document in
   the database
•  Emits key/value pairs
   –  Can emit 0, 1, or more KV pairs for each document
      in the database
   –  Keys and values can be complex data structures
•  KV pairs are then ordered and indexed by key

                  Introduction to CouchDB
                  Open Source Business Systems
   www.opusvl.com
Queries
                                  

•  Queries are run against views
   –  i.e. searches the "key" of the list of KV pairs
•  Query types:
   –  Exact: key = x
   –  Range: key is between x and y
   –  Multiple: key is in list (x,y,z) 


•  Reduce functions
   –  e.g. count, sum, group

                   Introduction to CouchDB
                   Open Source Business Systems
    www.opusvl.com
Designing a view

•  Show messages for a specific user
  // This is JavaScript

  function(doc) {
      if (doc.type && doc.to && doc.text) {
          if (doc.type == 'message') {
              for (var dest in doc.to) {
                  emit(doc.to[dest], doc.text);
              }
          }
      }
  }


                Introduction to CouchDB
                Open Source Business Systems
   www.opusvl.com
Creating a view

•  Can either use the GUI or the API

•  View stored in database as a "Design Document"
   –  A design document can contain multiple views


•  Example
   –  Design document "_design/myview"
   –  View name "messages_to"


                 Introduction to CouchDB
                 Open Source Business Systems
   www.opusvl.com
Querying a view
use Data::Dumper;

my $client = CouchDB::Client->new();
my $db     = $client->newDB('jj_test');
my $view   = $db->newDesignDoc('_design/myview')
                ->retrieve;

my $result = try {
    $view->queryView('messages_to', (key => 'JJ'));
} catch {
    die "Could not query view";
};

say Dumper($result);

              Introduction to CouchDB
              Open Source Business Systems
   www.opusvl.com
Query results
                                

varos:talk_scripts jj$ perl5.10.1 query_view.pl

$VAR1 = {
             'total_rows' => 3,
             'rows' => [
                          {
                            'value' => 'Hello, World',
                            'id' => 'docid',
                            'key' => 'JJ'
                          }
                       ],
             'offset' => 2
        };


                  Introduction to CouchDB
                  Open Source Business Systems
   www.opusvl.com
Conclusion
                                

•  Different mindset to SQL database
•  Quite low-level, but very powerful
•  Additional features
   –  Replication
   –  Document revisions
   –  Reduce functions
   –  Changes API


•  More information: http://books.couchdb.org/relax 

                  Introduction to CouchDB
                  Open Source Business Systems
   www.opusvl.com
KTHKSBYE!
                 


Thank you for listening!

          Any questions?
                       
    http://www.opusvl.com
 http://perl.jonallen.info/talks 


      Introduction to CouchDB
      Open Source Business Systems
   www.opusvl.com

More Related Content

What's hot

The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPressTaylor Lovett
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPressTaylor Lovett
 
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + ThymeleafDSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + ThymeleafTim Donohue
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleRaimonds Simanovskis
 
Vibe Custom Development
Vibe Custom DevelopmentVibe Custom Development
Vibe Custom DevelopmentGWAVA
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Custom Development with Novell Teaming
Custom Development with Novell TeamingCustom Development with Novell Teaming
Custom Development with Novell TeamingNovell
 
Put a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastPut a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastOSCON Byrum
 
Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Taylor Lovett
 
Rapid prototyping with solr - By Erik Hatcher
Rapid prototyping with solr -  By Erik Hatcher Rapid prototyping with solr -  By Erik Hatcher
Rapid prototyping with solr - By Erik Hatcher lucenerevolution
 
Website designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentWebsite designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentCss Founder
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails IntroductionThomas Fuchs
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchTaylor Lovett
 

What's hot (19)

The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPress
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
Mini Rails Framework
Mini Rails FrameworkMini Rails Framework
Mini Rails Framework
 
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + ThymeleafDSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Rack
RackRack
Rack
 
Vibe Custom Development
Vibe Custom DevelopmentVibe Custom Development
Vibe Custom Development
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Custom Development with Novell Teaming
Custom Development with Novell TeamingCustom Development with Novell Teaming
Custom Development with Novell Teaming
 
Php converted pdf
Php converted pdfPhp converted pdf
Php converted pdf
 
Ppt php
Ppt phpPpt php
Ppt php
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Put a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastPut a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going Fast
 
Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch
 
Rapid prototyping with solr - By Erik Hatcher
Rapid prototyping with solr -  By Erik Hatcher Rapid prototyping with solr -  By Erik Hatcher
Rapid prototyping with solr - By Erik Hatcher
 
Web Ninja
Web NinjaWeb Ninja
Web Ninja
 
Website designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentWebsite designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopment
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails Introduction
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
 

Similar to Introduction to CouchDB

Introduction to couchdb
Introduction to couchdbIntroduction to couchdb
Introduction to couchdbiammutex
 
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaSolutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaGuido Schmutz
 
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...confluent
 
Introduction to couch_db
Introduction to couch_dbIntroduction to couch_db
Introduction to couch_dbRomain Testard
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemdelagoya
 
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaSolutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaGuido Schmutz
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
CouchDB and Rails on the Cloud
CouchDB and Rails on the CloudCouchDB and Rails on the Cloud
CouchDB and Rails on the Cloudrockyjaiswal
 
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...IndicThreads
 
Intro to CouchDB
Intro to CouchDBIntro to CouchDB
Intro to CouchDBsbisbee
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App ArchitectureCorey Butler
 
Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DBMihail Mateev
 
Ruby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingRuby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingDan Davis
 
Icinga 2009 at OSMC
Icinga 2009 at OSMCIcinga 2009 at OSMC
Icinga 2009 at OSMCIcinga
 
NoSQL - "simple" web monitoring
NoSQL - "simple" web monitoringNoSQL - "simple" web monitoring
NoSQL - "simple" web monitoringSamir Siqueira
 

Similar to Introduction to CouchDB (20)

Introduction to couchdb
Introduction to couchdbIntroduction to couchdb
Introduction to couchdb
 
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaSolutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
 
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
 
Introduction to couch_db
Introduction to couch_dbIntroduction to couch_db
Introduction to couch_db
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problem
 
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaSolutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
CouchDB and Rails on the Cloud
CouchDB and Rails on the CloudCouchDB and Rails on the Cloud
CouchDB and Rails on the Cloud
 
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
 
Introduction to RavenDB
Introduction to RavenDBIntroduction to RavenDB
Introduction to RavenDB
 
Couchdb Nosql
Couchdb NosqlCouchdb Nosql
Couchdb Nosql
 
Introduction to RavenDB
Introduction to RavenDBIntroduction to RavenDB
Introduction to RavenDB
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
 
Intro to CouchDB
Intro to CouchDBIntro to CouchDB
Intro to CouchDB
 
מיכאל
מיכאלמיכאל
מיכאל
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App Architecture
 
Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DB
 
Ruby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingRuby on Rails All Hands Meeting
Ruby on Rails All Hands Meeting
 
Icinga 2009 at OSMC
Icinga 2009 at OSMCIcinga 2009 at OSMC
Icinga 2009 at OSMC
 
NoSQL - "simple" web monitoring
NoSQL - "simple" web monitoringNoSQL - "simple" web monitoring
NoSQL - "simple" web monitoring
 

Recently uploaded

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 

Recently uploaded (20)

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 

Introduction to CouchDB

  • 1. Introduction to CouchDB Jon Allen (JJ) – jj@opusvl.com YAPC::Europe 2010 Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 2. What is CouchDB? •  Document Oriented Database Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 3. What is CouchDB? •  Document Oriented Database –  No schema •  Stores "documents" (i.e. data structures) –  No SQL •  Uses "MapReduce" queries written in JavaScript Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 4. What is CouchDB? •  Document Oriented Database –  No schema •  Stores "documents" (i.e. data structures) –  No SQL •  Uses "MapReduce" queries written in JavaScript •  Written in Erlang •  REST API •  Replication, scalability Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 5. Why use CouchDB? •  Store complex data structures (JSON) •  Store variable data structures (no schema) •  De-normalised / self contained •  Add attachments to documents •  Scalable and fault tolerant •  Better fit for certain problem domains –  Messaging –  CMS Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 6. Using CouchDB from Perl •  HTTP REST API •  No DBI, DBD, DBIx::Class etc •  CPAN modules –  CouchDB::Client –  AnyEvent::CouchDB Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 7. Creating a database use CouchDB::Client; use Try::Tiny; my $client = CouchDB::Client->new( uri => 'http://localhost:5984' ); my $db = $client->newDB('jj_test'); # lower case! try { $db->create; } catch { die "Could not create DB"; }; Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 8. Inserting a document my $client = CouchDB::Client->new(); my $db = $client->newDB('jj_test'); my $doc = $db->newDoc('docid', undef, { type => 'message', text => 'Hello, World', to => ['JJ', 'Barbie', 'Brian'], }); try { $doc->create; } catch { die "Could not create document"; }; Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 9. Inserting a document my $client = CouchDB::Client->new(); my $db = $client->newDB('jj_test'); my $doc = $db->newDoc('docid', undef, { type => 'message', text => 'Hello, World', to => ['JJ', 'Barbie', 'Brian'], }); try { Document ID, Revision ID $doc->create; must be unique } catch { die "Could not create document"; }; Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 10. CouchDB GUI Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 11. Querying documents All Documents Map function Key, Value Key, Value Key, Value Query by Key Key, Value Key, Value Key, Value Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 12. Views •  A view is a JavaScript function –  Like a stored procedure in SQL •  Map function is executed on every document in the database •  Emits key/value pairs –  Can emit 0, 1, or more KV pairs for each document in the database –  Keys and values can be complex data structures •  KV pairs are then ordered and indexed by key Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 13. Queries •  Queries are run against views –  i.e. searches the "key" of the list of KV pairs •  Query types: –  Exact: key = x –  Range: key is between x and y –  Multiple: key is in list (x,y,z) •  Reduce functions –  e.g. count, sum, group Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 14. Designing a view •  Show messages for a specific user // This is JavaScript function(doc) { if (doc.type && doc.to && doc.text) { if (doc.type == 'message') { for (var dest in doc.to) { emit(doc.to[dest], doc.text); } } } } Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 15. Creating a view •  Can either use the GUI or the API •  View stored in database as a "Design Document" –  A design document can contain multiple views •  Example –  Design document "_design/myview" –  View name "messages_to" Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 16. Querying a view use Data::Dumper; my $client = CouchDB::Client->new(); my $db = $client->newDB('jj_test'); my $view = $db->newDesignDoc('_design/myview') ->retrieve; my $result = try { $view->queryView('messages_to', (key => 'JJ')); } catch { die "Could not query view"; }; say Dumper($result); Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 17. Query results varos:talk_scripts jj$ perl5.10.1 query_view.pl $VAR1 = { 'total_rows' => 3, 'rows' => [ { 'value' => 'Hello, World', 'id' => 'docid', 'key' => 'JJ' } ], 'offset' => 2 }; Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 18. Conclusion •  Different mindset to SQL database •  Quite low-level, but very powerful •  Additional features –  Replication –  Document revisions –  Reduce functions –  Changes API •  More information: http://books.couchdb.org/relax Introduction to CouchDB Open Source Business Systems www.opusvl.com
  • 19. KTHKSBYE! Thank you for listening! Any questions? http://www.opusvl.com http://perl.jonallen.info/talks Introduction to CouchDB Open Source Business Systems www.opusvl.com