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

Post on 17-May-2015

997 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

Node.js with MongoDB in action...

TRANSCRIPT

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

MiCloud Team Benson

Big User

什麼是NoSQL

Big Data

什麼是NoSQL

五大特性

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

什麼是NoSQL

NoSQL的種類與特性

NoSQL的種類與特性

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

About Mongo DB

Database == DatabaseCollections == TableDocument == Row

mongoDB VS SQL

安裝Mongodb

實作Nodejs and MongoDB

範例程式

http://goo.gl/SbvZPx

● 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) {});

程式實作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) {});

程式實作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) {});

程式實作Delete Document

//刪除單一筆

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

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

collection.remove();

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

Map-Reduce

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

MAP

Map-Reduce

什麼是Reduce

Map-Reduce

Map-Reduce

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

NoSQL知名案例

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

http://www.mongodb.org/

其他資源

謝謝大家

top related