SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Dernier (20)

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 

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