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


              Jon Allen (JJ)
                           

  http://perl.jonallen.info - jj@jonallen.info
What is CouchDB?
  •  Document Oriented Database




Introduction to CouchDB	

                perl.jonallen.info
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	

                           perl.jonallen.info
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	

                           perl.jonallen.info
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	

                      perl.jonallen.info
Using CouchDB from Perl
                                      
  •  HTTP REST API
  •  No DBI, DBD, DBIx::Class etc

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




Introduction to CouchDB	

            perl.jonallen.info
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	

                       perl.jonallen.info
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	

                         perl.jonallen.info
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	

                           perl.jonallen.info
CouchDB GUI
                                       




Introduction to CouchDB	

                 perl.jonallen.info
Querying documents
                                      

            All                             Map function
         Documents




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

                                             Key, Value
                                                      



Introduction to CouchDB	

                      perl.jonallen.info
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	

                            perl.jonallen.info
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	

                                   perl.jonallen.info
Designing a view
  •  Show messages for a specific user
      my $view = <<EOT;
          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);
                      }
                  }
              }
          }
      EOT



Introduction to CouchDB	

                      perl.jonallen.info
Creating a view
      my $client = CouchDB::Client->new();
      my $db     = $client->newDB('jj_test');

      my $doc     = $db->newDesignDoc('_design/myview',undef,
      {
          views => {
              messages_to => { map => $view },
          },
      });

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

Introduction to CouchDB	

                       perl.jonallen.info
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	

                      perl.jonallen.info
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	

                             perl.jonallen.info
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	

                   perl.jonallen.info
KTHKSBYE!


                 Thank you for listening!

                             Any questions?
                                          
                    http://perl.jonallen.info/talks 




Introduction to CouchDB	

                              perl.jonallen.info

More Related Content

What's hot

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBLee Theobald
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB Habilelabs
 
NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and HowBigBlueHat
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBBradley Holt
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverMongoDB
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Dbchriskite
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App ArchitectureCorey Butler
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node jsHabilelabs
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDBAlex Sharp
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql DatabasePrashant Gupta
 

What's hot (20)

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 
CouchDB
CouchDBCouchDB
CouchDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
CouchDB
CouchDBCouchDB
CouchDB
 
NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and How
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDB
 
Mongo db operations_v2
Mongo db operations_v2Mongo db operations_v2
Mongo db operations_v2
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
 
Apache CouchDB
Apache CouchDBApache CouchDB
Apache CouchDB
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App Architecture
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node js
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql Database
 

Viewers also liked

Training: the (Not So) Secret Key to Repository Sustainability
Training: the (Not So) Secret Key to Repository SustainabilityTraining: the (Not So) Secret Key to Repository Sustainability
Training: the (Not So) Secret Key to Repository Sustainabilityeosadler
 
Promotions executive kpi
Promotions executive kpiPromotions executive kpi
Promotions executive kpifuresdavit
 
Cis336 week 5 i lab 5
Cis336 week 5 i lab 5Cis336 week 5 i lab 5
Cis336 week 5 i lab 5jackiechaner
 
A Model for Activity Recognition in Pervasive Enviornment Inspired by Global ...
A Model for Activity Recognition in Pervasive Enviornment Inspired by Global ...A Model for Activity Recognition in Pervasive Enviornment Inspired by Global ...
A Model for Activity Recognition in Pervasive Enviornment Inspired by Global ...Mahdi Nasseri
 
II Guerra Mundial
II Guerra MundialII Guerra Mundial
II Guerra Mundialagatagc
 
Tiger sec posting order
Tiger sec posting orderTiger sec posting order
Tiger sec posting orderdineshangirish
 
Przentacja o kwiatach
Przentacja o kwiatachPrzentacja o kwiatach
Przentacja o kwiatachnela007
 
ใบความรู้ กลุ่มทางเศรษฐกิจ+497+dltvsocp6+54soc p06 f26-1page
ใบความรู้  กลุ่มทางเศรษฐกิจ+497+dltvsocp6+54soc p06 f26-1pageใบความรู้  กลุ่มทางเศรษฐกิจ+497+dltvsocp6+54soc p06 f26-1page
ใบความรู้ กลุ่มทางเศรษฐกิจ+497+dltvsocp6+54soc p06 f26-1pagePrachoom Rangkasikorn
 
Everything Must Go exhibition opens for one weekend only
Everything Must Go exhibition opens for one weekend only Everything Must Go exhibition opens for one weekend only
Everything Must Go exhibition opens for one weekend only brakqd41ba
 
School nr 5
School nr 5School nr 5
School nr 5Mairi
 
Biotalousstrategian työpaja: Toimenpideohjelma
Biotalousstrategian työpaja: ToimenpideohjelmaBiotalousstrategian työpaja: Toimenpideohjelma
Biotalousstrategian työpaja: ToimenpideohjelmaBiotalous.fi
 
물뽕 3방울이면 박근혜도 미친년으로 된다.【카톡:SKP999 & DDF11.KR】물뽕 50mg정품파는곳,물뽕 50mg구입,물뽕 50mg팝니...
물뽕 3방울이면 박근혜도 미친년으로 된다.【카톡:SKP999 & DDF11.KR】물뽕 50mg정품파는곳,물뽕 50mg구입,물뽕 50mg팝니...물뽕 3방울이면 박근혜도 미친년으로 된다.【카톡:SKP999 & DDF11.KR】물뽕 50mg정품파는곳,물뽕 50mg구입,물뽕 50mg팝니...
물뽕 3방울이면 박근혜도 미친년으로 된다.【카톡:SKP999 & DDF11.KR】물뽕 50mg정품파는곳,물뽕 50mg구입,물뽕 50mg팝니...tnauswprndl ghb
 
What Customer Loyalty Means To Me!
What Customer Loyalty Means To Me!What Customer Loyalty Means To Me!
What Customer Loyalty Means To Me!Christina Green
 
The 3 Roots of Evil
The 3 Roots of Evil The 3 Roots of Evil
The 3 Roots of Evil OH TEIK BIN
 

Viewers also liked (20)

Socialtools
SocialtoolsSocialtools
Socialtools
 
9
99
9
 
Training: the (Not So) Secret Key to Repository Sustainability
Training: the (Not So) Secret Key to Repository SustainabilityTraining: the (Not So) Secret Key to Repository Sustainability
Training: the (Not So) Secret Key to Repository Sustainability
 
Ivan
IvanIvan
Ivan
 
Promotions executive kpi
Promotions executive kpiPromotions executive kpi
Promotions executive kpi
 
Dfsi Group1
Dfsi Group1Dfsi Group1
Dfsi Group1
 
Cis336 week 5 i lab 5
Cis336 week 5 i lab 5Cis336 week 5 i lab 5
Cis336 week 5 i lab 5
 
A Model for Activity Recognition in Pervasive Enviornment Inspired by Global ...
A Model for Activity Recognition in Pervasive Enviornment Inspired by Global ...A Model for Activity Recognition in Pervasive Enviornment Inspired by Global ...
A Model for Activity Recognition in Pervasive Enviornment Inspired by Global ...
 
II Guerra Mundial
II Guerra MundialII Guerra Mundial
II Guerra Mundial
 
Tiger sec posting order
Tiger sec posting orderTiger sec posting order
Tiger sec posting order
 
QUESTION 1
QUESTION 1QUESTION 1
QUESTION 1
 
Przentacja o kwiatach
Przentacja o kwiatachPrzentacja o kwiatach
Przentacja o kwiatach
 
ใบความรู้ กลุ่มทางเศรษฐกิจ+497+dltvsocp6+54soc p06 f26-1page
ใบความรู้  กลุ่มทางเศรษฐกิจ+497+dltvsocp6+54soc p06 f26-1pageใบความรู้  กลุ่มทางเศรษฐกิจ+497+dltvsocp6+54soc p06 f26-1page
ใบความรู้ กลุ่มทางเศรษฐกิจ+497+dltvsocp6+54soc p06 f26-1page
 
Everything Must Go exhibition opens for one weekend only
Everything Must Go exhibition opens for one weekend only Everything Must Go exhibition opens for one weekend only
Everything Must Go exhibition opens for one weekend only
 
School nr 5
School nr 5School nr 5
School nr 5
 
Biotalousstrategian työpaja: Toimenpideohjelma
Biotalousstrategian työpaja: ToimenpideohjelmaBiotalousstrategian työpaja: Toimenpideohjelma
Biotalousstrategian työpaja: Toimenpideohjelma
 
물뽕 3방울이면 박근혜도 미친년으로 된다.【카톡:SKP999 & DDF11.KR】물뽕 50mg정품파는곳,물뽕 50mg구입,물뽕 50mg팝니...
물뽕 3방울이면 박근혜도 미친년으로 된다.【카톡:SKP999 & DDF11.KR】물뽕 50mg정품파는곳,물뽕 50mg구입,물뽕 50mg팝니...물뽕 3방울이면 박근혜도 미친년으로 된다.【카톡:SKP999 & DDF11.KR】물뽕 50mg정품파는곳,물뽕 50mg구입,물뽕 50mg팝니...
물뽕 3방울이면 박근혜도 미친년으로 된다.【카톡:SKP999 & DDF11.KR】물뽕 50mg정품파는곳,물뽕 50mg구입,물뽕 50mg팝니...
 
What Customer Loyalty Means To Me!
What Customer Loyalty Means To Me!What Customer Loyalty Means To Me!
What Customer Loyalty Means To Me!
 
Foro de debate y argumentación gr
Foro de debate y argumentación grForo de debate y argumentación gr
Foro de debate y argumentación gr
 
The 3 Roots of Evil
The 3 Roots of Evil The 3 Roots of Evil
The 3 Roots of Evil
 

Similar to Introduction to couchdb

Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDBOpusVL
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
Introduction to couch_db
Introduction to couch_dbIntroduction to couch_db
Introduction to couch_dbRomain Testard
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
Cooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with ChefCooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with ChefG. Ryan Fawcett
 
Spring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataSpring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataRoger Xia
 
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
 
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
 
Introduction to ArangoDB (nosql matters Barcelona 2012)
Introduction to ArangoDB (nosql matters Barcelona 2012)Introduction to ArangoDB (nosql matters Barcelona 2012)
Introduction to ArangoDB (nosql matters Barcelona 2012)ArangoDB Database
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Editionddiers
 
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
 
Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)Sean Cribbs
 

Similar to Introduction to couchdb (20)

Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDB
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Introduction to couch_db
Introduction to couch_dbIntroduction to couch_db
Introduction to couch_db
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
Cooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with ChefCooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with Chef
 
Spring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataSpring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_data
 
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...
 
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
 
Introduction to ArangoDB (nosql matters Barcelona 2012)
Introduction to ArangoDB (nosql matters Barcelona 2012)Introduction to ArangoDB (nosql matters Barcelona 2012)
Introduction to ArangoDB (nosql matters Barcelona 2012)
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
 
No sql Database
No sql DatabaseNo sql Database
No sql Database
 
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
 
Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)
 
Introduction to RavenDB
Introduction to RavenDBIntroduction to RavenDB
Introduction to RavenDB
 
Mongodb my
Mongodb myMongodb my
Mongodb my
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
jQuery Objects
jQuery ObjectsjQuery Objects
jQuery Objects
 
Hive jdbc
Hive jdbcHive jdbc
Hive jdbc
 

More from iammutex

Scaling Instagram
Scaling InstagramScaling Instagram
Scaling Instagramiammutex
 
Redis深入浅出
Redis深入浅出Redis深入浅出
Redis深入浅出iammutex
 
深入了解Redis
深入了解Redis深入了解Redis
深入了解Redisiammutex
 
NoSQL误用和常见陷阱分析
NoSQL误用和常见陷阱分析NoSQL误用和常见陷阱分析
NoSQL误用和常见陷阱分析iammutex
 
MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用iammutex
 
8 minute MongoDB tutorial slide
8 minute MongoDB tutorial slide8 minute MongoDB tutorial slide
8 minute MongoDB tutorial slideiammutex
 
Thoughts on Transaction and Consistency Models
Thoughts on Transaction and Consistency ModelsThoughts on Transaction and Consistency Models
Thoughts on Transaction and Consistency Modelsiammutex
 
Rethink db&tokudb调研测试报告
Rethink db&tokudb调研测试报告Rethink db&tokudb调研测试报告
Rethink db&tokudb调研测试报告iammutex
 
redis 适用场景与实现
redis 适用场景与实现redis 适用场景与实现
redis 适用场景与实现iammutex
 
What every data programmer needs to know about disks
What every data programmer needs to know about disksWhat every data programmer needs to know about disks
What every data programmer needs to know about disksiammutex
 
redis运维之道
redis运维之道redis运维之道
redis运维之道iammutex
 
Realtime hadoopsigmod2011
Realtime hadoopsigmod2011Realtime hadoopsigmod2011
Realtime hadoopsigmod2011iammutex
 
[译]No sql生态系统
[译]No sql生态系统[译]No sql生态系统
[译]No sql生态系统iammutex
 
Couchdb + Membase = Couchbase
Couchdb + Membase = CouchbaseCouchdb + Membase = Couchbase
Couchdb + Membase = Couchbaseiammutex
 
Redis cluster
Redis clusterRedis cluster
Redis clusteriammutex
 
Redis cluster
Redis clusterRedis cluster
Redis clusteriammutex
 
Hadoop introduction berlin buzzwords 2011
Hadoop introduction   berlin buzzwords 2011Hadoop introduction   berlin buzzwords 2011
Hadoop introduction berlin buzzwords 2011iammutex
 

More from iammutex (20)

Scaling Instagram
Scaling InstagramScaling Instagram
Scaling Instagram
 
Redis深入浅出
Redis深入浅出Redis深入浅出
Redis深入浅出
 
深入了解Redis
深入了解Redis深入了解Redis
深入了解Redis
 
NoSQL误用和常见陷阱分析
NoSQL误用和常见陷阱分析NoSQL误用和常见陷阱分析
NoSQL误用和常见陷阱分析
 
MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用
 
8 minute MongoDB tutorial slide
8 minute MongoDB tutorial slide8 minute MongoDB tutorial slide
8 minute MongoDB tutorial slide
 
skip list
skip listskip list
skip list
 
Thoughts on Transaction and Consistency Models
Thoughts on Transaction and Consistency ModelsThoughts on Transaction and Consistency Models
Thoughts on Transaction and Consistency Models
 
Rethink db&tokudb调研测试报告
Rethink db&tokudb调研测试报告Rethink db&tokudb调研测试报告
Rethink db&tokudb调研测试报告
 
redis 适用场景与实现
redis 适用场景与实现redis 适用场景与实现
redis 适用场景与实现
 
What every data programmer needs to know about disks
What every data programmer needs to know about disksWhat every data programmer needs to know about disks
What every data programmer needs to know about disks
 
Ooredis
OoredisOoredis
Ooredis
 
Ooredis
OoredisOoredis
Ooredis
 
redis运维之道
redis运维之道redis运维之道
redis运维之道
 
Realtime hadoopsigmod2011
Realtime hadoopsigmod2011Realtime hadoopsigmod2011
Realtime hadoopsigmod2011
 
[译]No sql生态系统
[译]No sql生态系统[译]No sql生态系统
[译]No sql生态系统
 
Couchdb + Membase = Couchbase
Couchdb + Membase = CouchbaseCouchdb + Membase = Couchbase
Couchdb + Membase = Couchbase
 
Redis cluster
Redis clusterRedis cluster
Redis cluster
 
Redis cluster
Redis clusterRedis cluster
Redis cluster
 
Hadoop introduction berlin buzzwords 2011
Hadoop introduction   berlin buzzwords 2011Hadoop introduction   berlin buzzwords 2011
Hadoop introduction berlin buzzwords 2011
 

Recently uploaded

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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Introduction to couchdb

  • 1. Introduction to CouchDB Jon Allen (JJ) http://perl.jonallen.info - jj@jonallen.info
  • 2. What is CouchDB? •  Document Oriented Database Introduction to CouchDB perl.jonallen.info
  • 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 perl.jonallen.info
  • 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 perl.jonallen.info
  • 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 perl.jonallen.info
  • 6. Using CouchDB from Perl •  HTTP REST API •  No DBI, DBD, DBIx::Class etc •  CPAN modules –  CouchDB::Client –  AnyEvent::CouchDB Introduction to CouchDB perl.jonallen.info
  • 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 perl.jonallen.info
  • 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 perl.jonallen.info
  • 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 perl.jonallen.info
  • 10. CouchDB GUI Introduction to CouchDB perl.jonallen.info
  • 11. Querying documents All Map function Documents Key, Value Key, Value Key, Value Query by Key Key, Value Key, Value Key, Value Introduction to CouchDB perl.jonallen.info
  • 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 perl.jonallen.info
  • 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 perl.jonallen.info
  • 14. Designing a view •  Show messages for a specific user my $view = <<EOT; 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); } } } } EOT Introduction to CouchDB perl.jonallen.info
  • 15. Creating a view my $client = CouchDB::Client->new(); my $db = $client->newDB('jj_test'); my $doc = $db->newDesignDoc('_design/myview',undef, { views => { messages_to => { map => $view }, }, }); try { $doc->create; } catch { die "Could not create document"; }; Introduction to CouchDB perl.jonallen.info
  • 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 perl.jonallen.info
  • 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 perl.jonallen.info
  • 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 perl.jonallen.info
  • 19. KTHKSBYE! Thank you for listening! Any questions? http://perl.jonallen.info/talks Introduction to CouchDB perl.jonallen.info