Your SlideShare is downloading. ×
0
NodeJS & NoSQL          PPT: http://goo.gl/nHQRJCode: https://github.com/peihsinsu/nko2012.git              Simon Su      ...
課程大綱●   三分鐘簡介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
About NoSQL
NoSQL Size vs Complexity   From: http://www.slideshare.net/quipo/nosql-databases-why-what-and-when
relaxMy Choice
Why CouchDB● Implemention for ACID Properties    ○ Multi-Version Concurrency Control (MVCC)    ○ B-Tree indexes●   Schema-...
User Friendly of CouchDB ● Install: http://wiki.apache.org/couchdb/Installationconfiguration                              ...
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 2012Start to using NoSQL
Node.js NoSQL environment# express product# vi package.json (add cradle and other package relations...)# cd product# npm i...
Connect to NoSQLdb = new(cradle.Connection)(  db_address,  db_port,  {auth: { username: dbusername, password: dbpassword},...
NoSQL Basic CRUD● [C] 新增一筆資料,id=PK,doc=欲儲存文件,callback=回傳  觸發事件:  db.save(id, doc, callback);● [R] 查詢資料,id=欲查詢的資料id,callbac...
Schema-Freevar cradle = require(cradle);var db = new(cradle.Connection)().database(starwars);db.save(skywalker,       doc-...
Schema mapping to RDBMS             Document to save, free schema and dynamic NoSQL       change.     Key         skywalke...
NoSQL最佳使用方式●   離散資料 - 無特定規則可循●   原始資料 - 不正規化、不特別處理●   以Map / Reduce重新規劃資料呈現方式●   搭配RESTful使用(http://goo.gl/iEKDR)
Node Knock Out 2012NoSQL Map / Reduce
View Model - Map / Reduce
View Model - Map / Reduce
Example Data - Guess Game Raw{    "_id":"1350783674236",    "_rev":"1-fed6ba9a837d66c8fb086b32294d5f7d",    "sessionid":"1...
CouchDB Design - Map Functionfunction(doc) {  if(doc.data){                                                        列舉data並...
CouchDB Design - Reduce Functionfunction(key, values, rereduce){                                   將原資料型態({player: player_...
Node Knock Out 2012NoSQL 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-an...
Reference 2: Some Acronyms● RDBMS: Relational Database Management System.● SQL: Structured Query Language, also used to re...
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=s...
Nko workshop - node js & nosql
Upcoming SlideShare
Loading in...5
×

Nko workshop - node js & nosql

2,793

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,793
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
27
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Nko workshop - node js & nosql"

  1. 1. NodeJS & NoSQL PPT: http://goo.gl/nHQRJCode: https://github.com/peihsinsu/nko2012.git Simon Su simonsu.mail@gmail.com
  2. 2. 課程大綱● 三分鐘簡介NoSQL● 初入NoSQL的選擇● Node.js使用CouchDB● CouchDB Map / Reduce介紹● CouchDB Administration簡介
  3. 3. Why NoSQL - We Need Store... File Store (R)DBMS
  4. 4. We Need Store - Trouble in RDBMS From: http://www.slideshare.net/quipo/nosql-databases-why-what-and-when
  5. 5. What is NoSQL NoSQL = Not-Only-SQL
  6. 6. About NoSQL
  7. 7. NoSQL Size vs Complexity From: http://www.slideshare.net/quipo/nosql-databases-why-what-and-when
  8. 8. relaxMy Choice
  9. 9. 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.
  10. 10. User Friendly of CouchDB ● Install: http://wiki.apache.org/couchdb/Installationconfiguration status check query user auth. management replocate REST server
  11. 11. User Friendly of CouchDB● [GET] http://ipaddress:5984/database/column_key
  12. 12. CouchDB PaaS Services● Cloudant http://cloudant.com● IrisCouch http://www.iriscouch.com/
  13. 13. Node Knock Out 2012Start to using NoSQL
  14. 14. Node.js NoSQL environment# express product# vi package.json (add cradle and other package relations...)# cd product# npm install https://github.com/cloudhead/cradle
  15. 15. Connect to NoSQLdb = new(cradle.Connection)( db_address, db_port, {auth: { username: dbusername, password: dbpassword}, cache: true, raw: false}).database(databasename);
  16. 16. 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);
  17. 17. Schema-Freevar 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
  18. 18. 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 allRDBMS data effected DML id (pk) force name sex skywalker light Luke Skywalker ... ... ... ...
  19. 19. NoSQL最佳使用方式● 離散資料 - 無特定規則可循● 原始資料 - 不正規化、不特別處理● 以Map / Reduce重新規劃資料呈現方式● 搭配RESTful使用(http://goo.gl/iEKDR)
  20. 20. Node Knock Out 2012NoSQL Map / Reduce
  21. 21. View Model - Map / Reduce
  22. 22. View Model - Map / Reduce
  23. 23. Example Data - Guess Game Raw{ "_id":"1350783674236", "_rev":"1-fed6ba9a837d66c8fb086b32294d5f7d", "sessionid":"1350783674236", "data":[ { "player":"3WAUD..EZOHQ", "name":"Caesar Chi", "score":2 } ]}
  24. 24. CouchDB Design - Map Functionfunction(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資料
  25. 25. CouchDB Design - Reduce Functionfunction(key, values, rereduce){ 將原資料型態({player: player_id, name: return sum(values); player_name}: score)其中的Score以作分} 組(group by key)加總 Source: 以{user資訊: 答對題目數} 為資料型態的資料 Result: 以user資訊為群組,加總答對題目 數,建立相同資料型態的資料
  26. 26. Node Knock Out 2012NoSQL Administration
  27. 27. Replicate Database Replicate
  28. 28. Single Server Replicate
  29. 29. CouchDB Cluster Service
  30. 30. Node Knock Out 2012 Q&A
  31. 31. 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
  32. 32. 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
  33. 33. Node Knock Out 2012 附錄
  34. 34. 範例與執行● Code: test-couchdb.js● Execute:
  35. 35. Node Knock Out 2012 After Class...
  36. 36. CouchDB Related● CouchDB sorting related - View Collection http://wiki.apache.org/couchdb/View_collation? action=show&redirect=ViewCollation
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×