Nko workshop - node js & nosql
Upcoming SlideShare
Loading in...5

Nko workshop - node js & nosql






Total Views
Views on SlideShare
Embed Views



9 Embeds 182

http://peihsinsu.blogspot.tw 148
http://peihsinsu.blogspot.com 15
http://peihsinsu.blogspot.hk 8
http://nodeslide.herokuapp.com 4
http://www.directrss.co.il 2
http://www.rxx.co.il 2
http://peihsinsu.blogspot.ca 1
http://peihsinsu.blogspot.fr 1
http://peihsinsu.blogspot.de 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Nko workshop - node js & nosql Nko workshop - node js & nosql Presentation Transcript

  • NodeJS & NoSQL PPT: http://goo.gl/nHQRJCode: 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 View slide
  • We Need Store - Trouble in RDBMS From: http://www.slideshare.net/quipo/nosql-databases-why-what-and-when View slide
  • 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-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/Installationconfiguration 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 2012Start 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 NoSQLdb = 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-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
  • 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 ... ... ... ...
  • 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":"1350783674236", "data":[ { "player":"3WAUD..EZOHQ", "name":"Caesar Chi", "score":2 } ]}
  • 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資料
  • 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資訊為群組,加總答對題目 數,建立相同資料型態的資料
  • 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-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