Top Banner
進階使用Nodejs-淺談 NoSQL(MongoDB) MiCloud Team Benson
21

進階使用Nodejs 淺談no sql(mongodb)

May 17, 2015

Download

Technology

Simon Su

Node.js with MongoDB in action...
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 進階使用Nodejs 淺談no sql(mongodb)

進階使用Nodejs-淺談NoSQL(MongoDB)

MiCloud Team Benson

Page 2: 進階使用Nodejs 淺談no sql(mongodb)

Big User

什麼是NoSQL

Page 3: 進階使用Nodejs 淺談no sql(mongodb)

Big Data

什麼是NoSQL

Page 4: 進階使用Nodejs 淺談no sql(mongodb)

五大特性

● Not Only SQL● 水平擴充資料庫容量● No Schema● 資料遲早一致● 新技術成熟度不足,版本風險

什麼是NoSQL

Page 5: 進階使用Nodejs 淺談no sql(mongodb)

NoSQL的種類與特性

Page 6: 進階使用Nodejs 淺談no sql(mongodb)

NoSQL的種類與特性

Page 7: 進階使用Nodejs 淺談no sql(mongodb)

● Open Source● Document database● Written in C++● Bson

About Mongo DB

Page 8: 進階使用Nodejs 淺談no sql(mongodb)

Database == DatabaseCollections == TableDocument == Row

mongoDB VS SQL

Page 9: 進階使用Nodejs 淺談no sql(mongodb)

安裝Mongodb

實作Nodejs and MongoDB

Page 10: 進階使用Nodejs 淺談no sql(mongodb)

範例程式

http://goo.gl/SbvZPx

Page 11: 進階使用Nodejs 淺談no sql(mongodb)

● npm install mongodb

程式實作Create document

var doc1 = {'hello':'doc1'}; var doc2 = {'hello':'doc2'}; var lotsOfDocs = [{'hello':'doc3'}, {'hello':'doc4'}];

collection.insert(doc1);

collection.insert(doc2, {w:1}, function(err, result) {});

collection.insert(lotsOfDocs, {w:1}, function(err, result) {});

Page 12: 進階使用Nodejs 淺談no sql(mongodb)

程式實作Query document

//查詢全部

collection.find().toArray(function(err, items) {}) //除了2以外

var stream = collection.find({mykey:{$ne:2}}).stream(); stream.on("data", function(item) {}); stream.on("end", function() {}); //單一筆

collection.findOne({mykey:1}, function(err, item) {});

Page 13: 進階使用Nodejs 淺談no sql(mongodb)

程式實作update document

collection.update({mykey:1}, {$set:{fieldtoupdate:2}}, {w:1}, function(err, result) {}); collection.update({mykey:2}, {$push:{docs:{doc2:1}}}, {w:1}, function(err, result) {});

Page 14: 進階使用Nodejs 淺談no sql(mongodb)

程式實作Delete Document

//刪除單一筆

collection.remove({mykey:1}); //刪除單一筆並傳回結果

collection.remove({mykey:2}, {w:1}, function(err, result) {}); //刪除全部

collection.remove();

Page 15: 進階使用Nodejs 淺談no sql(mongodb)

什麼是 Map● Function● 平行獨立,不影響原 Collection

Map-Reduce

Collection[{key: value},{key: value},{key: value}]

MAP

Page 16: 進階使用Nodejs 淺談no sql(mongodb)

Map-Reduce

Page 17: 進階使用Nodejs 淺談no sql(mongodb)

什麼是Reduce

Map-Reduce

Page 18: 進階使用Nodejs 淺談no sql(mongodb)

Map-Reduce

Page 19: 進階使用Nodejs 淺談no sql(mongodb)

● Facebook (Cassandra , HBase)● Twitter (Cassandra, HBase)● Yahoo(HBase)● 力可科技(Cassandra)

NoSQL知名案例

Page 20: 進階使用Nodejs 淺談no sql(mongodb)

● MongoHQ http://www.mongohq.com/home● mongoDB

http://www.mongodb.org/

其他資源

Page 21: 進階使用Nodejs 淺談no sql(mongodb)

謝謝大家