SlideShare a Scribd company logo
NodeJS & NoSQL
          PPT: http://goo.gl/nHQRJ
Code: https://github.com/peihsinsu/nko2012.git



              Simon Su
       simonsu.mail@gmail.com
課程大綱

●   三分鐘簡介NoSQL
●   初入NoSQL的選擇
●   Node.js使用CouchDB
●   CouchDB Map / Reduce介紹
●   CouchDB Administration簡介
Why NoSQL - We Need Store...




      File Store      (R)DBMS
We Need Store - Trouble in RDBMS




    From: http://www.slideshare.net/quipo/nosql-databases-why-what-and-when
What is NoSQL

   NoSQL = Not-Only-SQL
Nko workshop - node js & nosql
About NoSQL
NoSQL Size vs Complexity




   From: http://www.slideshare.net/quipo/nosql-databases-why-what-and-when
relax

My Choice
Why CouchDB
● Implemention for ACID Properties
    ○ Multi-Version Concurrency Control (MVCC)
    ○ B-Tree indexes
●   Schema-Free document-oriented database
●   RESTful default support (JSON document)
●   View model / JavaScript View Functions
●   Replication (Peer-based distributed
    databases), Distributed, featuring robust,
    incremental replication with bi-directional
    conflict detection and management.
User Friendly of CouchDB
 ● Install: http://wiki.apache.org/couchdb/Installation




configuration
                                                                status check

                query

                                                   user auth.
                                                  management
                        replocate
                                    REST server
User Friendly of CouchDB
● [GET] http://ipaddress:5984/database/column_key
CouchDB PaaS Services
● Cloudant
  http://cloudant.com
● IrisCouch
  http://www.iriscouch.com/
Node Knock Out 2012


Start to using NoSQL
Node.js NoSQL environment
# express product
# vi package.json (add cradle and other package relations...)
# cd product
# npm install



        https://github.com/cloudhead/cradle
Connect to NoSQL
db = new(cradle.Connection)(
  db_address,
  db_port,
  {auth: { username: dbusername, password: dbpassword},
  cache: true,
  raw: false
}).database(databasename);
NoSQL Basic CRUD
● [C] 新增一筆資料,id=PK,doc=欲儲存文件,callback=回傳
  觸發事件:
  db.save(id, doc, callback);
● [R] 查詢資料,id=欲查詢的資料id,callback=同上:
  db.get(id, callback);
● [U] 修改一筆資料,id=欲修改之資料id,doc=欲修改的文件
  內容,callback同上:
  db.merge(id, doc, callback);
● [D] 刪除資料,id=PK,rev=版本號碼,callback同上:
  db.remove(id, rev, callback);
Schema-Free
var cradle = require('cradle');
var db = new(cradle.Connection)().database('starwars');
db.save('skywalker',       doc-key
{
   force: 'light',
   name: 'Luke Skywalker'         document

}, callback);


                starwars
                     Key     skywalker

                     Value   force   name

                             light   Luke
                                     Skywalker
Schema mapping to RDBMS
             Document to save, free schema and dynamic
 NoSQL       change.

     Key         skywalker

     Value       force          name                   ---

                 light          Luke Skywalker         ---

                 force          name                   sex

                 light          Richard W.             M



             Schema create first, insert later...
             Every column add, need schema update, and all
RDBMS        data effected                                              DML

     id (pk)              force                  name             sex

     skywalker            light                  Luke Skywalker

     ...                  ...                    ...              ...
NoSQL最佳使用方式

●   離散資料 - 無特定規則可循
●   原始資料 - 不正規化、不特別處理
●   以Map / Reduce重新規劃資料呈現方式
●   搭配RESTful使用(http://goo.gl/iEKDR)
Node Knock Out 2012


NoSQL Map / Reduce
View Model - Map / Reduce
View Model - Map / Reduce
Example Data - Guess Game Raw
{
    "_id":"1350783674236",
    "_rev":"1-fed6ba9a837d66c8fb086b32294d5f7d",
    "sessionid":"1350783674236",
    "data":[
         {
             "player":"3WAUD..EZOHQ",
             "name":"Caesar Chi",
             "score":2
         }
    ]
}
CouchDB Design - Map Function
function(doc) {
  if(doc.data){
                                                        列舉data並以
    for(var i = 0 ; i < doc.data.length ; i++ ) {       ({player: player_id, name: player_name}: score)
      if(doc.data[i].player && doc.data[i].score){      建立View
        emit({player:doc.data[i].player,name:doc.data[i].name}, doc.data[i].score);
      }
    }
  }
}



Source:
一筆scores資料




    Result:
    一筆view資料
CouchDB Design - Reduce Function
function(key, values, rereduce){
                                   將原資料型態({player: player_id, name:
  return sum(values);              player_name}: score)其中的Score以作分
}                                  組(group by key)加總




   Source:
   以{user資訊: 答對題目數}
   為資料型態的資料




                            Result:
                            以user資訊為群組,加總答對題目
                            數,建立相同資料型態的資料
Node Knock Out 2012


NoSQL Administration
Replicate Database




               Replicate
Single Server Replicate
CouchDB Cluster Service
Node Knock Out 2012


       Q&A
Reference
●   不做NoSQL的CouchDB: http://www.openfoundry.org/tw/tech-column/8301--nosql-couchdb
●   nosql-databases-why-what-and-when: http://www.slideshare.net/quipo/nosql-databases-why-
    what-and-when
●   Neo4J: http://neo4j.tw/
●   Couchdb REST samples: http://peihsinsu.blogspot.tw/search?q=couchdb
●   Couch View: http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
Reference 2: Some Acronyms
● RDBMS: Relational Database Management System.
● SQL: Structured Query Language, also used to refer to
    databases that use SQL as their query language.
●   NoSQL: Also called Distributed Database Management
    Systems, used to refer to a class of databases that are
    non-relational and do not use SQL as their query
    language.
●   ACID: Atomicity, Consistency, Isolation, Durability.
●   CAP: Consistency, Availability, Partition tolerance.
●   MVCC: Multi-Version Concurency Control
Node Knock Out 2012


       附錄
範例與執行

● Code: test-couchdb.js
● Execute:
Node Knock Out 2012


    After Class...
CouchDB Related
●   CouchDB sorting related - View Collection
    http://wiki.apache.org/couchdb/View_collation?
    action=show&redirect=ViewCollation

More Related Content

What's hot (20)

PDF
Introduction to Apache Tajo: Data Warehouse for Big Data
Gruter
 
PDF
An introduction to MongoDB
Universidade de São Paulo
 
PPTX
Introduction to HDFS
Siddharth Mathur
 
PPTX
Mongo DB 102
Abhijeet Vaikar
 
PDF
CFS: Cassandra backed storage for Hadoop
nickmbailey
 
ODP
Drupal MySQL Cluster
Kris Buytaert
 
PPT
2 db2 instance creation
Ravikumar Nandigam
 
PDF
Understanding blue store, Ceph's new storage backend - Tim Serong, SUSE
OpenStack
 
PDF
Gluster.next feb-2016
Vijay Bellur
 
PDF
MySQL Document Store -- SCaLE 17x Presentation
Dave Stokes
 
PDF
An introduction To Apache Spark
Amir Sedighi
 
PDF
Introduction of mesos persistent storage
Zhou Weitao
 
PPT
9b. Document-Oriented Databases lab
Fabio Fumarola
 
PDF
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
Insight Technology, Inc.
 
PDF
Heuritech: Apache Spark REX
didmarin
 
PDF
Kerberizing spark. Spark Summit east
Jorge Lopez-Malla
 
PDF
Use Your MySQL Knowledge to Become a MongoDB Guru
Tim Callaghan
 
PPTX
MongoDB - External Authentication
Jason Terpko
 
PPTX
Openstack glance
SHAMEEM F
 
PPTX
MongoDB Best Practices for Developers
Moshe Kaplan
 
Introduction to Apache Tajo: Data Warehouse for Big Data
Gruter
 
An introduction to MongoDB
Universidade de São Paulo
 
Introduction to HDFS
Siddharth Mathur
 
Mongo DB 102
Abhijeet Vaikar
 
CFS: Cassandra backed storage for Hadoop
nickmbailey
 
Drupal MySQL Cluster
Kris Buytaert
 
2 db2 instance creation
Ravikumar Nandigam
 
Understanding blue store, Ceph's new storage backend - Tim Serong, SUSE
OpenStack
 
Gluster.next feb-2016
Vijay Bellur
 
MySQL Document Store -- SCaLE 17x Presentation
Dave Stokes
 
An introduction To Apache Spark
Amir Sedighi
 
Introduction of mesos persistent storage
Zhou Weitao
 
9b. Document-Oriented Databases lab
Fabio Fumarola
 
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
Insight Technology, Inc.
 
Heuritech: Apache Spark REX
didmarin
 
Kerberizing spark. Spark Summit east
Jorge Lopez-Malla
 
Use Your MySQL Knowledge to Become a MongoDB Guru
Tim Callaghan
 
MongoDB - External Authentication
Jason Terpko
 
Openstack glance
SHAMEEM F
 
MongoDB Best Practices for Developers
Moshe Kaplan
 

Viewers also liked (8)

PDF
Google I/O Extended 2016 - 台北場活動回顧
Simon Su
 
PDF
HTML5 WebSockets
Harri Hämäläinen
 
PDF
JCConf2016 - Dataflow Workshop Setup
Simon Su
 
PDF
JCConf 2016 - Dataflow Workshop Labs
Simon Su
 
PDF
Docker in Action
Simon Su
 
PDF
GCPUG meetup 201610 - Dataflow Introduction
Simon Su
 
PDF
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
Simon Su
 
PDF
JCConf 2016 - Google Dataflow 小試
Simon Su
 
Google I/O Extended 2016 - 台北場活動回顧
Simon Su
 
HTML5 WebSockets
Harri Hämäläinen
 
JCConf2016 - Dataflow Workshop Setup
Simon Su
 
JCConf 2016 - Dataflow Workshop Labs
Simon Su
 
Docker in Action
Simon Su
 
GCPUG meetup 201610 - Dataflow Introduction
Simon Su
 
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
Simon Su
 
JCConf 2016 - Google Dataflow 小試
Simon Su
 
Ad

Similar to Nko workshop - node js & nosql (20)

PPTX
JS App Architecture
Corey Butler
 
PDF
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
Inhacking
 
PDF
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Аліна Шепшелей
 
PPTX
Example R usage for oracle DBA UKOUG 2013
BertrandDrouvot
 
PPTX
DAC4B 2015 - Polybase
Łukasz Grala
 
PDF
Couchbas for dummies
Qureshi Tehmina
 
PDF
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
CloudxLab
 
PPTX
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
PDF
Spark SQL - 10 Things You Need to Know
Kristian Alexander
 
PDF
MongoDB and DynamoDB
Md. Minhazul Haque
 
ODP
Slickdemo
Knoldus Inc.
 
KEY
About Data::ObjectDriver
Yoshiki Kurihara
 
PDF
Los Angeles R users group - Dec 14 2010 - Part 2
rusersla
 
PDF
Introducing Apache Spark's Data Frames and Dataset APIs workshop series
Holden Karau
 
PDF
Integrating data stored in rdbms and hadoop
leorick lin
 
PPTX
Introduce to Spark sql 1.3.0
Bryan Yang
 
PPT
Drill / SQL / Optiq
Julian Hyde
 
PDF
[SSA] 03.newsql database (2014.02.05)
Steve Min
 
PDF
Sqoop Explanation with examples and syntax
dspyanand
 
PDF
MySQL up and running 30 minutes.pdf
Vinicius M Grippa
 
JS App Architecture
Corey Butler
 
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
Inhacking
 
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Аліна Шепшелей
 
Example R usage for oracle DBA UKOUG 2013
BertrandDrouvot
 
DAC4B 2015 - Polybase
Łukasz Grala
 
Couchbas for dummies
Qureshi Tehmina
 
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
CloudxLab
 
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
Spark SQL - 10 Things You Need to Know
Kristian Alexander
 
MongoDB and DynamoDB
Md. Minhazul Haque
 
Slickdemo
Knoldus Inc.
 
About Data::ObjectDriver
Yoshiki Kurihara
 
Los Angeles R users group - Dec 14 2010 - Part 2
rusersla
 
Introducing Apache Spark's Data Frames and Dataset APIs workshop series
Holden Karau
 
Integrating data stored in rdbms and hadoop
leorick lin
 
Introduce to Spark sql 1.3.0
Bryan Yang
 
Drill / SQL / Optiq
Julian Hyde
 
[SSA] 03.newsql database (2014.02.05)
Steve Min
 
Sqoop Explanation with examples and syntax
dspyanand
 
MySQL up and running 30 minutes.pdf
Vinicius M Grippa
 
Ad

More from Simon Su (20)

PDF
Kubernetes Basic Operation
Simon Su
 
PDF
Google IoT Core 初體驗
Simon Su
 
PDF
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
Simon Su
 
PDF
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
Simon Su
 
PDF
Google Cloud Platform Special Training
Simon Su
 
PDF
GCE Windows Serial Console Usage Guide
Simon Su
 
PDF
GCPNext17' Extend 開始GCP了嗎?
Simon Su
 
PDF
Try Cloud Spanner
Simon Su
 
PDF
Google Cloud Monitoring
Simon Su
 
PDF
Google Cloud Computing compares GCE, GAE and GKE
Simon Su
 
PDF
Brocade - Stingray Application Firewall
Simon Su
 
PDF
Google I/O 2016 Recap - Google Cloud Platform News Update
Simon Su
 
PDF
IThome DevOps Summit - IoT、docker與DevOps
Simon Su
 
PDF
Google Cloud Platform Introduction - 2016Q3
Simon Su
 
PPTX
GCS - Access Control Lists (中文)
Simon Su
 
PDF
Google Cloud Platform - for Mobile Solutions
Simon Su
 
PDF
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)
Simon Su
 
PDF
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
Simon Su
 
PDF
GCPUG.TW - 2016活動討論
Simon Su
 
PDF
GCPUG.TW - 2015活動回顧
Simon Su
 
Kubernetes Basic Operation
Simon Su
 
Google IoT Core 初體驗
Simon Su
 
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
Simon Su
 
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
Simon Su
 
Google Cloud Platform Special Training
Simon Su
 
GCE Windows Serial Console Usage Guide
Simon Su
 
GCPNext17' Extend 開始GCP了嗎?
Simon Su
 
Try Cloud Spanner
Simon Su
 
Google Cloud Monitoring
Simon Su
 
Google Cloud Computing compares GCE, GAE and GKE
Simon Su
 
Brocade - Stingray Application Firewall
Simon Su
 
Google I/O 2016 Recap - Google Cloud Platform News Update
Simon Su
 
IThome DevOps Summit - IoT、docker與DevOps
Simon Su
 
Google Cloud Platform Introduction - 2016Q3
Simon Su
 
GCS - Access Control Lists (中文)
Simon Su
 
Google Cloud Platform - for Mobile Solutions
Simon Su
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)
Simon Su
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
Simon Su
 
GCPUG.TW - 2016活動討論
Simon Su
 
GCPUG.TW - 2015活動回顧
Simon Su
 

Recently uploaded (20)

PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 

Nko workshop - node js & nosql

  • 1. NodeJS & NoSQL PPT: http://goo.gl/nHQRJ Code: https://github.com/peihsinsu/nko2012.git Simon Su [email protected]
  • 2. 課程大綱 ● 三分鐘簡介NoSQL ● 初入NoSQL的選擇 ● Node.js使用CouchDB ● CouchDB Map / Reduce介紹 ● CouchDB Administration簡介
  • 3. Why NoSQL - We Need Store... File Store (R)DBMS
  • 4. We Need Store - Trouble in RDBMS From: http://www.slideshare.net/quipo/nosql-databases-why-what-and-when
  • 5. What is NoSQL NoSQL = Not-Only-SQL
  • 8. NoSQL Size vs Complexity From: http://www.slideshare.net/quipo/nosql-databases-why-what-and-when
  • 10. Why CouchDB ● Implemention for ACID Properties ○ Multi-Version Concurrency Control (MVCC) ○ B-Tree indexes ● Schema-Free document-oriented database ● RESTful default support (JSON document) ● View model / JavaScript View Functions ● Replication (Peer-based distributed databases), Distributed, featuring robust, incremental replication with bi-directional conflict detection and management.
  • 11. User Friendly of CouchDB ● Install: http://wiki.apache.org/couchdb/Installation configuration status check query user auth. management replocate REST server
  • 12. User Friendly of CouchDB ● [GET] http://ipaddress:5984/database/column_key
  • 13. CouchDB PaaS Services ● Cloudant http://cloudant.com ● IrisCouch http://www.iriscouch.com/
  • 14. Node Knock Out 2012 Start to using NoSQL
  • 15. Node.js NoSQL environment # express product # vi package.json (add cradle and other package relations...) # cd product # npm install https://github.com/cloudhead/cradle
  • 16. Connect to NoSQL db = new(cradle.Connection)( db_address, db_port, {auth: { username: dbusername, password: dbpassword}, cache: true, raw: false }).database(databasename);
  • 17. NoSQL Basic CRUD ● [C] 新增一筆資料,id=PK,doc=欲儲存文件,callback=回傳 觸發事件: db.save(id, doc, callback); ● [R] 查詢資料,id=欲查詢的資料id,callback=同上: db.get(id, callback); ● [U] 修改一筆資料,id=欲修改之資料id,doc=欲修改的文件 內容,callback同上: db.merge(id, doc, callback); ● [D] 刪除資料,id=PK,rev=版本號碼,callback同上: db.remove(id, rev, callback);
  • 18. Schema-Free var cradle = require('cradle'); var db = new(cradle.Connection)().database('starwars'); db.save('skywalker', doc-key { force: 'light', name: 'Luke Skywalker' document }, callback); starwars Key skywalker Value force name light Luke Skywalker
  • 19. Schema mapping to RDBMS Document to save, free schema and dynamic NoSQL change. Key skywalker Value force name --- light Luke Skywalker --- force name sex light Richard W. M Schema create first, insert later... Every column add, need schema update, and all RDBMS data effected DML id (pk) force name sex skywalker light Luke Skywalker ... ... ... ...
  • 20. NoSQL最佳使用方式 ● 離散資料 - 無特定規則可循 ● 原始資料 - 不正規化、不特別處理 ● 以Map / Reduce重新規劃資料呈現方式 ● 搭配RESTful使用(http://goo.gl/iEKDR)
  • 21. Node Knock Out 2012 NoSQL Map / Reduce
  • 22. View Model - Map / Reduce
  • 23. View Model - Map / Reduce
  • 24. Example Data - Guess Game Raw { "_id":"1350783674236", "_rev":"1-fed6ba9a837d66c8fb086b32294d5f7d", "sessionid":"1350783674236", "data":[ { "player":"3WAUD..EZOHQ", "name":"Caesar Chi", "score":2 } ] }
  • 25. CouchDB Design - Map Function function(doc) { if(doc.data){ 列舉data並以 for(var i = 0 ; i < doc.data.length ; i++ ) { ({player: player_id, name: player_name}: score) if(doc.data[i].player && doc.data[i].score){ 建立View emit({player:doc.data[i].player,name:doc.data[i].name}, doc.data[i].score); } } } } Source: 一筆scores資料 Result: 一筆view資料
  • 26. CouchDB Design - Reduce Function function(key, values, rereduce){ 將原資料型態({player: player_id, name: return sum(values); player_name}: score)其中的Score以作分 } 組(group by key)加總 Source: 以{user資訊: 答對題目數} 為資料型態的資料 Result: 以user資訊為群組,加總答對題目 數,建立相同資料型態的資料
  • 27. Node Knock Out 2012 NoSQL Administration
  • 28. Replicate Database Replicate
  • 31. Node Knock Out 2012 Q&A
  • 32. Reference ● 不做NoSQL的CouchDB: http://www.openfoundry.org/tw/tech-column/8301--nosql-couchdb ● nosql-databases-why-what-and-when: http://www.slideshare.net/quipo/nosql-databases-why- what-and-when ● Neo4J: http://neo4j.tw/ ● Couchdb REST samples: http://peihsinsu.blogspot.tw/search?q=couchdb ● Couch View: http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
  • 33. Reference 2: Some Acronyms ● RDBMS: Relational Database Management System. ● SQL: Structured Query Language, also used to refer to databases that use SQL as their query language. ● NoSQL: Also called Distributed Database Management Systems, used to refer to a class of databases that are non-relational and do not use SQL as their query language. ● ACID: Atomicity, Consistency, Isolation, Durability. ● CAP: Consistency, Availability, Partition tolerance. ● MVCC: Multi-Version Concurency Control
  • 34. Node Knock Out 2012 附錄
  • 36. Node Knock Out 2012 After Class...
  • 37. CouchDB Related ● CouchDB sorting related - View Collection http://wiki.apache.org/couchdb/View_collation? action=show&redirect=ViewCollation