SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
Mokoversity 
MongoDB & NoSQL 101 
2014.9.24 
Jollen, Founder 
<jollen@jollen.org> 
www.mokoversity.com
Mokoversity 
認識 NoSQL 資料庫
NoSQL 
• Not Only SQL 
• Document-Oriented 
• Not a replacement for SQL database 
• Schema-less 
• Full Text Search, Data-processing, read 
faster, write faster 
• etc
Mokoversity 
Document-Oriented 與 JSON
Step Zero 
$ mongo! 
MongoDB shell version: 2.4.2! 
...! 
> ! 
> db! 
test! 
> show dbs! 
local! 0.078125GB! 
vcard! 0.203125GB! 
> use vcard! 
switched to db vcard! 
> 
Cards 
mongo 
db 
showdbs 
use
認識 Collections 
> use vcard! 
switched to db vcard! 
> show collections! 
messages! 
system.indexes! 
users! 
> exit! 
bye 
Cards 
show collections 
exit
什麼是 Collections 
• Document Store (aka folder) 
• In JSON and BSON format 
• aka XML、MS Word、MS Excel 
• Grouping documents 
• collections 
• Directory hierarchies 
• Collections could be considered analogous to 
tables
Key-Value Paris 
• Key–Value stores use the associative 
array 
• The fundamental data model of 
document store 
• In-memory document store 
• Memory Cache 
• Redis and etc.
Create a new Database 
$ mongo! 
! 
> show dbs! 
local! 0.078125GB! 
messages! 0.203125GB! 
test! 0.203125GB! 
> use mytest! 
switched to db mytest! 
> db.dropDatabase()! 
{ "dropped" : "mytest", "ok" : 1 } Cards 
use <new-db-name>
Save a new Document 
> use mytest! 
switched to db mytest! 
> db.mytest.save({name: 'jollen'})! 
> db.mytest.find()! 
{ "_id" : ObjectId("53bf7682af97b69f131d970a"), "name" : 
"jollen" }! 
> 
Cards 
save() 
find() 
⾃自動產⽣生
認識 Schema 
• NoSQL 資料庫不需要事先定義欄位 
• Table Definition 
• Document 的欄位定義稱為 Schema 
• Has Schema 或 No Schema
Query a Collection 
• find() 
• find({name: ‘Jollen’}) 
• findOne()
Remove a Document 
• remove() 
• remove({name: 'jollen'})
Update a Document 
• update({name: 'jollen2'}, {name: 
'jollen3'}) 
• update({name:'jollen'}, {$set: {name: 
'jollen2'}}, {multi: true}) 
Query criteria 
fields 
New document ! 
content 
http://docs.mongodb.org/manual/reference/method/db.collection.update/
基本的 CRUD 操作 
• find()-Read 
• Query Criteria 
• Projection 
• Aggregation 
• update()-Update 
• Query Criteria
學習要點 
• NoSQL 初學者應先學習 Collection 的操作 
• CRUD 
• 類似於使⽤用 SQL 語法做 Table 的查詢、新增、更新與 
刪除 
• 學習 Schema Design 觀念與實作 
• 學習 Query Criteria 
• 學習 Aggregation 
• MapReduce 的基礎
Query Criteria 
• 各式「條件查詢」的做法 
• {age: {$gt: 18} } 
• WHERE 
http://docs.mongodb.org/manual/core/read-operations/
Mokoversity 
MongoDB CRUD
Implement CRUD 
• MongoDB Shell 
• MongoDB Script 
• MongoDB Drivers 
• Node.js (JavaScript) 
• Python / Ruby 
• C / C++ 
• etc - http://docs.mongodb.org/ecosystem/drivers/
MongoDB Script 
• 使⽤用 JavaScript 語法 
• 進⾏行 CRUD 操作 
• 撰寫管理功能 
• 簡單的 Data Processing (MapReduce)
Create One Document 
// 0001! 
! 
{! 
var db = connect('localhost/test');! 
! 
db.vipData.save({name: 'jollen', tel: '09384567182'});! 
! 
print('0001-create-one-document finished.')! 
}
List Collection 
// 0002! 
! 
{! 
var db = connect('localhost/test');! 
! 
db.vipData.find().forEach(function(user) {! 
print("User: " + user.name + ", tel: " + user.tel);! 
});! 
! 
print("Info: 0002-list-collection finished.");! 
}!
Update Document 
// 0003! 
! 
{! 
var db = connect('localhost/test');! 
! 
db.vipData.update({name: 'jollen'}, { $set: {name: 
'jollenchen'} });! 
! 
print('0004-update-document finished');! 
}
Add News Field 
// 0004! 
! 
{! 
var db = connect('localhost/test');! 
! 
db.vipData.find().forEach(function(data) {! 
data.isActive = true;! 
db.vipData.save(data);! 
});! 
! 
print('0004-add-new-field finished');! 
}
Remove Document 
// 0005! 
! 
{! 
var db = connect('localhost/test');! 
! 
db.vipData.remove({name: 'jollen'});! 
! 
print('0005-remove-document finished.');! 
}
Mokoversity 
Schema Design
基本觀念 
• 類似關鍵式資料庫的 Table 設計 
• Flexible Schema
Schema 設計原則 
• When designing data models, always consider 
the application usage of the data (i.e. queries, 
updates, and processing of the data) as well as 
the inherent structure of the data itself. 
• There are two tools that allow applications to 
represent these relationships: references and 
embedded documents. 
• References 
• Embedded Data 
http://docs.mongodb.org/manual/core/data-modeling-introduction/
Embedded Document 
Post Collection 
_id 
title 
content 
tags 
Nickname 
Fullname 
Mobile 
Age
Reference Model 使⽤用原則 
• 亦稱為 Normalized Data Model 
• 主要⽤用途 
• One-to-Many Relations* 
• Many-to-Many Relations 
• 主要缺點 
• ⽂文件變⼤大時造成 write performance 變差
One-To-Many 的情況 #1 
{! 
_id: "joe",! 
name: "Joe Bookreader”,! 
address:! 
{! 
patron_id: "joe",! 
street: "123 Fake Street",! 
city: "Faketon",! 
state: "MA",! 
zip: "12345"! 
}! 
}! 
! 
{! 
_id: "joe",! 
name: "Joe Bookreader"! 
address:! 
{! 
patron_id: "joe",! 
street: "1 Some Other Street",! 
city: "Boston",! 
state: "MA",! 
zip: “12345"! 
}! 
}
Reference Model 
http://docs.mongodb.org/manual/core/data-modeling-introduction/
關於 Reference Model 
• 建議使⽤用的 Data Model 
• Using references between documents 
• Avoid duplication of data 
• Provide sufficient read performance advantage
Schema Design 
User Collection 
_id 
name 
email 
address 
age Message Collection 
_id 
message 
uid
專案描述 
• 將 Microsoft Excel 資料庫,轉換⾄至 NoSQL 
的開發任務 
• 客⼾戶資料是以 Excel 維護,現在想將客⼾戶資 
料「上雲端」,並製作 App 以隨時追蹤或查 
詢 
• 將客⼾戶資料轉換為 NoSQL 資料庫。以便進 
⾏行 RESTful Web Service 的開發,以及 App 
的製作
CRUD: Task 1 
• 建⽴立 vcard 資料庫 
• 新增資料⾄至 vcard.users collections 
• 資料欄位 
• name 
• phone 
• email 
• address 
• age
提⽰示 
• 將 users.xls 匯⼊入 vcard.users collection 
• 註:users.xls 是程式產⽣生的假資料,⾮非真實 
資料
CRUD: Task 2 
• 新增資料⾄至 vcard.messages collections 
• 資料欄位 
• uid(紀錄 ObjectId) 
• message(⽂文章內⽂文)
Mokoversity 
Aggregation (MapReduce)
使⽤用 Query Criteria 
http://docs.mongodb.org/manual/core/crud-introduction/
CRUD: Task 3 
• 公司想針對 45 歲以下的客⼾戶進⾏行⾏行銷推廣 
• 找出 18 歲以上的客⼾戶
使⽤用 Aggregation 
exports.query = function(req, res) {! 
! var model = req.app.db.models.User;! 
! 
! model! 
! .aggregate([! 
{! 
! $project: { _id: 1, name: 1, age: 1 }! 
},! 
{! 
! $match: {age: {$gt: 45} }! 
},! 
{! 
! $match: {age: {$lt: 60} }! 
}])! 
! .exec(function(err, users) {! 
! ! res.send(users);! 
! ! res.end();! 
! });! 
}
Mokoversity 
REST API-Using 
Node.js 
and mongoose
REST API 規劃
認識 CRUD
User Collection 的 Schema 
// Model name: ‘User’! 
var userSchema = new mongoose.Schema({! 
name: { type: String, default: ''},! 
email: String,! 
address: String,! 
age: { type: Number, default: 0 }! 
}); 
User Collection 
name 
email 
address 
age
Message Collection 的 Schema 
// Model name: ‘Message’! 
var messageSchema = new mongoose.Schema({! 
uid: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },! 
message: String! 
}); 
Message Collection 
_id 
message 
uid
使⽤用 $in Operator 
• 興趣有 ‘sport’ 的會員 
{ interests: { $in: [ 'sport' ] } }
Populate 
model! 
.find()! 
.populate('uid')! 
.exec(function(err, posts) {! 
res.send(posts);! 
res.end();! 
});

Weitere ähnliche Inhalte

Was ist angesagt?

OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
 
Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)Mike West
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shintutorialsruby
 
Simpler Core Data with RubyMotion
Simpler Core Data with RubyMotionSimpler Core Data with RubyMotion
Simpler Core Data with RubyMotionStefan Haflidason
 
Intorduction of Playframework
Intorduction of PlayframeworkIntorduction of Playframework
Intorduction of Playframeworkmaltiyadav
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Ayes Chinmay
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...mfrancis
 
前端MVC之BackboneJS
前端MVC之BackboneJS前端MVC之BackboneJS
前端MVC之BackboneJSZhang Xiaoxue
 
DMDW Extra Lesson - NoSql and MongoDB
DMDW  Extra Lesson - NoSql and MongoDBDMDW  Extra Lesson - NoSql and MongoDB
DMDW Extra Lesson - NoSql and MongoDBJohannes Hoppe
 
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und HibernateEffiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und HibernateThorben Janssen
 
Database madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyDatabase madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyJaime Buelta
 
Hdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed SolutionsHdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed Solutionswoutervugt
 
Templates
TemplatesTemplates
Templatessoon
 
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...Sencha
 

Was ist angesagt? (20)

OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shin
 
RicoLiveGrid
RicoLiveGridRicoLiveGrid
RicoLiveGrid
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Simpler Core Data with RubyMotion
Simpler Core Data with RubyMotionSimpler Core Data with RubyMotion
Simpler Core Data with RubyMotion
 
Intorduction of Playframework
Intorduction of PlayframeworkIntorduction of Playframework
Intorduction of Playframework
 
NoSQL - Hands on
NoSQL - Hands onNoSQL - Hands on
NoSQL - Hands on
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
 
Doctrine and NoSQL
Doctrine and NoSQLDoctrine and NoSQL
Doctrine and NoSQL
 
Doctrine for NoSQL
Doctrine for NoSQLDoctrine for NoSQL
Doctrine for NoSQL
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
 
前端MVC之BackboneJS
前端MVC之BackboneJS前端MVC之BackboneJS
前端MVC之BackboneJS
 
DMDW Extra Lesson - NoSql and MongoDB
DMDW  Extra Lesson - NoSql and MongoDBDMDW  Extra Lesson - NoSql and MongoDB
DMDW Extra Lesson - NoSql and MongoDB
 
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und HibernateEffiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
 
Database madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyDatabase madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemy
 
Hdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed SolutionsHdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed Solutions
 
Templates
TemplatesTemplates
Templates
 
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
 

Andere mochten auch

Learning React - I
Learning React - ILearning React - I
Learning React - IMitch Chen
 
Django with Mongo using Mongoengine
Django with Mongo using MongoengineDjango with Mongo using Mongoengine
Django with Mongo using Mongoenginedudarev
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!Daniel Cousineau
 
word2vec, LDA, and introducing a new hybrid algorithm: lda2vec
word2vec, LDA, and introducing a new hybrid algorithm: lda2vecword2vec, LDA, and introducing a new hybrid algorithm: lda2vec
word2vec, LDA, and introducing a new hybrid algorithm: lda2vec👋 Christopher Moody
 
Mongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP DevelopersMongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP DevelopersRick Hightower
 

Andere mochten auch (6)

Learning React - I
Learning React - ILearning React - I
Learning React - I
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Django with Mongo using Mongoengine
Django with Mongo using MongoengineDjango with Mongo using Mongoengine
Django with Mongo using Mongoengine
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
word2vec, LDA, and introducing a new hybrid algorithm: lda2vec
word2vec, LDA, and introducing a new hybrid algorithm: lda2vecword2vec, LDA, and introducing a new hybrid algorithm: lda2vec
word2vec, LDA, and introducing a new hybrid algorithm: lda2vec
 
Mongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP DevelopersMongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP Developers
 

Ähnlich wie MongoDB & NoSQL 101

The Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsThe Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsMatias Cascallares
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
From SQL to MongoDB
From SQL to MongoDBFrom SQL to MongoDB
From SQL to MongoDBNuxeo
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlTO THE NEW | Technology
 
SQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The MoveSQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The MoveIBM Cloud Data Services
 
Sqlite
SqliteSqlite
SqliteKumar
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBSean Laurent
 
Intresting changes in mongo 2.6
Intresting changes in mongo 2.6Intresting changes in mongo 2.6
Intresting changes in mongo 2.6David Murphy
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBMongoDB
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsTeamstudio
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverMongoDB
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)MongoDB
 
NoSQL databases and managing big data
NoSQL databases and managing big dataNoSQL databases and managing big data
NoSQL databases and managing big dataSteven Francia
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewAntonio Pintus
 
Lessons from the Trenches - Building Enterprise Applications with RavenDB
Lessons from the Trenches - Building Enterprise Applications with RavenDBLessons from the Trenches - Building Enterprise Applications with RavenDB
Lessons from the Trenches - Building Enterprise Applications with RavenDBOren Eini
 

Ähnlich wie MongoDB & NoSQL 101 (20)

The Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsThe Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
 
Document db
Document dbDocument db
Document db
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
From SQL to MongoDB
From SQL to MongoDBFrom SQL to MongoDB
From SQL to MongoDB
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
SQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The MoveSQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The Move
 
Sqlite
SqliteSqlite
Sqlite
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB and Schema Design
MongoDB and Schema DesignMongoDB and Schema Design
MongoDB and Schema Design
 
Intresting changes in mongo 2.6
Intresting changes in mongo 2.6Intresting changes in mongo 2.6
Intresting changes in mongo 2.6
 
MongoDB_ppt.pptx
MongoDB_ppt.pptxMongoDB_ppt.pptx
MongoDB_ppt.pptx
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDB
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
MediaGlu and Mongo DB
MediaGlu and Mongo DBMediaGlu and Mongo DB
MediaGlu and Mongo DB
 
NoSQL databases and managing big data
NoSQL databases and managing big dataNoSQL databases and managing big data
NoSQL databases and managing big data
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overview
 
Lessons from the Trenches - Building Enterprise Applications with RavenDB
Lessons from the Trenches - Building Enterprise Applications with RavenDBLessons from the Trenches - Building Enterprise Applications with RavenDB
Lessons from the Trenches - Building Enterprise Applications with RavenDB
 

Mehr von Jollen Chen

Flowchain blockchain classroom at Taiwan Tech University
Flowchain blockchain classroom at Taiwan Tech UniversityFlowchain blockchain classroom at Taiwan Tech University
Flowchain blockchain classroom at Taiwan Tech UniversityJollen Chen
 
Bitmark and Hyperledger Workshop: the Digital Assets and Property
Bitmark and Hyperledger Workshop: the Digital Assets and PropertyBitmark and Hyperledger Workshop: the Digital Assets and Property
Bitmark and Hyperledger Workshop: the Digital Assets and PropertyJollen Chen
 
Introducing the Blockchain and Distributed Ledger Technology
Introducing the Blockchain and  Distributed Ledger TechnologyIntroducing the Blockchain and  Distributed Ledger Technology
Introducing the Blockchain and Distributed Ledger TechnologyJollen Chen
 
Maker of Things - the open IoT cloud for makers chapter.
Maker of Things - the open IoT cloud for makers chapter.Maker of Things - the open IoT cloud for makers chapter.
Maker of Things - the open IoT cloud for makers chapter.Jollen Chen
 
WoT.City and IoT Protocols Movement @ Taipei, Taiwan
WoT.City and IoT Protocols Movement @ Taipei, TaiwanWoT.City and IoT Protocols Movement @ Taipei, Taiwan
WoT.City and IoT Protocols Movement @ Taipei, TaiwanJollen Chen
 
IoT and Maker Crossover (IMCO) Conference 2015
IoT and Maker Crossover (IMCO) Conference 2015IoT and Maker Crossover (IMCO) Conference 2015
IoT and Maker Crossover (IMCO) Conference 2015Jollen Chen
 
Open IoT Cloud Architecture, Web of Things, Shenzhen, China.
Open IoT Cloud Architecture, Web of Things, Shenzhen, China.Open IoT Cloud Architecture, Web of Things, Shenzhen, China.
Open IoT Cloud Architecture, Web of Things, Shenzhen, China.Jollen Chen
 
Backbone.js and MVW 101
Backbone.js and MVW 101Backbone.js and MVW 101
Backbone.js and MVW 101Jollen Chen
 
Single-Page Application Design Principles 101
Single-Page Application Design Principles 101Single-Page Application Design Principles 101
Single-Page Application Design Principles 101Jollen Chen
 
Mokoversity Course: Apple Swift 101 - Introduction
Mokoversity Course: Apple Swift 101 - IntroductionMokoversity Course: Apple Swift 101 - Introduction
Mokoversity Course: Apple Swift 101 - IntroductionJollen Chen
 
Android Wear SDK: Level 101
Android Wear SDK: Level 101Android Wear SDK: Level 101
Android Wear SDK: Level 101Jollen Chen
 
Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3Jollen Chen
 
讓 HTML5 走進 IPTV Framework
讓 HTML5 走進 IPTV Framework讓 HTML5 走進 IPTV Framework
讓 HTML5 走進 IPTV FrameworkJollen Chen
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)Jollen Chen
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)Jollen Chen
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)Jollen Chen
 
Android HAL Introduction: libhardware and its legacy
Android HAL Introduction: libhardware and its legacyAndroid HAL Introduction: libhardware and its legacy
Android HAL Introduction: libhardware and its legacyJollen Chen
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen Chen
 
Embedded Linux: Introduction
Embedded Linux: IntroductionEmbedded Linux: Introduction
Embedded Linux: IntroductionJollen Chen
 
Android Application: Introduction
Android Application: IntroductionAndroid Application: Introduction
Android Application: IntroductionJollen Chen
 

Mehr von Jollen Chen (20)

Flowchain blockchain classroom at Taiwan Tech University
Flowchain blockchain classroom at Taiwan Tech UniversityFlowchain blockchain classroom at Taiwan Tech University
Flowchain blockchain classroom at Taiwan Tech University
 
Bitmark and Hyperledger Workshop: the Digital Assets and Property
Bitmark and Hyperledger Workshop: the Digital Assets and PropertyBitmark and Hyperledger Workshop: the Digital Assets and Property
Bitmark and Hyperledger Workshop: the Digital Assets and Property
 
Introducing the Blockchain and Distributed Ledger Technology
Introducing the Blockchain and  Distributed Ledger TechnologyIntroducing the Blockchain and  Distributed Ledger Technology
Introducing the Blockchain and Distributed Ledger Technology
 
Maker of Things - the open IoT cloud for makers chapter.
Maker of Things - the open IoT cloud for makers chapter.Maker of Things - the open IoT cloud for makers chapter.
Maker of Things - the open IoT cloud for makers chapter.
 
WoT.City and IoT Protocols Movement @ Taipei, Taiwan
WoT.City and IoT Protocols Movement @ Taipei, TaiwanWoT.City and IoT Protocols Movement @ Taipei, Taiwan
WoT.City and IoT Protocols Movement @ Taipei, Taiwan
 
IoT and Maker Crossover (IMCO) Conference 2015
IoT and Maker Crossover (IMCO) Conference 2015IoT and Maker Crossover (IMCO) Conference 2015
IoT and Maker Crossover (IMCO) Conference 2015
 
Open IoT Cloud Architecture, Web of Things, Shenzhen, China.
Open IoT Cloud Architecture, Web of Things, Shenzhen, China.Open IoT Cloud Architecture, Web of Things, Shenzhen, China.
Open IoT Cloud Architecture, Web of Things, Shenzhen, China.
 
Backbone.js and MVW 101
Backbone.js and MVW 101Backbone.js and MVW 101
Backbone.js and MVW 101
 
Single-Page Application Design Principles 101
Single-Page Application Design Principles 101Single-Page Application Design Principles 101
Single-Page Application Design Principles 101
 
Mokoversity Course: Apple Swift 101 - Introduction
Mokoversity Course: Apple Swift 101 - IntroductionMokoversity Course: Apple Swift 101 - Introduction
Mokoversity Course: Apple Swift 101 - Introduction
 
Android Wear SDK: Level 101
Android Wear SDK: Level 101Android Wear SDK: Level 101
Android Wear SDK: Level 101
 
Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3
 
讓 HTML5 走進 IPTV Framework
讓 HTML5 走進 IPTV Framework讓 HTML5 走進 IPTV Framework
讓 HTML5 走進 IPTV Framework
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
 
Android HAL Introduction: libhardware and its legacy
Android HAL Introduction: libhardware and its legacyAndroid HAL Introduction: libhardware and its legacy
Android HAL Introduction: libhardware and its legacy
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-level
 
Embedded Linux: Introduction
Embedded Linux: IntroductionEmbedded Linux: Introduction
Embedded Linux: Introduction
 
Android Application: Introduction
Android Application: IntroductionAndroid Application: Introduction
Android Application: Introduction
 

Kürzlich hochgeladen

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Kürzlich hochgeladen (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

MongoDB & NoSQL 101

  • 1. Mokoversity MongoDB & NoSQL 101 2014.9.24 Jollen, Founder <jollen@jollen.org> www.mokoversity.com
  • 3. NoSQL • Not Only SQL • Document-Oriented • Not a replacement for SQL database • Schema-less • Full Text Search, Data-processing, read faster, write faster • etc
  • 5. Step Zero $ mongo! MongoDB shell version: 2.4.2! ...! > ! > db! test! > show dbs! local! 0.078125GB! vcard! 0.203125GB! > use vcard! switched to db vcard! > Cards mongo db showdbs use
  • 6. 認識 Collections > use vcard! switched to db vcard! > show collections! messages! system.indexes! users! > exit! bye Cards show collections exit
  • 7. 什麼是 Collections • Document Store (aka folder) • In JSON and BSON format • aka XML、MS Word、MS Excel • Grouping documents • collections • Directory hierarchies • Collections could be considered analogous to tables
  • 8. Key-Value Paris • Key–Value stores use the associative array • The fundamental data model of document store • In-memory document store • Memory Cache • Redis and etc.
  • 9. Create a new Database $ mongo! ! > show dbs! local! 0.078125GB! messages! 0.203125GB! test! 0.203125GB! > use mytest! switched to db mytest! > db.dropDatabase()! { "dropped" : "mytest", "ok" : 1 } Cards use <new-db-name>
  • 10. Save a new Document > use mytest! switched to db mytest! > db.mytest.save({name: 'jollen'})! > db.mytest.find()! { "_id" : ObjectId("53bf7682af97b69f131d970a"), "name" : "jollen" }! > Cards save() find() ⾃自動產⽣生
  • 11. 認識 Schema • NoSQL 資料庫不需要事先定義欄位 • Table Definition • Document 的欄位定義稱為 Schema • Has Schema 或 No Schema
  • 12. Query a Collection • find() • find({name: ‘Jollen’}) • findOne()
  • 13. Remove a Document • remove() • remove({name: 'jollen'})
  • 14. Update a Document • update({name: 'jollen2'}, {name: 'jollen3'}) • update({name:'jollen'}, {$set: {name: 'jollen2'}}, {multi: true}) Query criteria fields New document ! content http://docs.mongodb.org/manual/reference/method/db.collection.update/
  • 15. 基本的 CRUD 操作 • find()-Read • Query Criteria • Projection • Aggregation • update()-Update • Query Criteria
  • 16. 學習要點 • NoSQL 初學者應先學習 Collection 的操作 • CRUD • 類似於使⽤用 SQL 語法做 Table 的查詢、新增、更新與 刪除 • 學習 Schema Design 觀念與實作 • 學習 Query Criteria • 學習 Aggregation • MapReduce 的基礎
  • 17. Query Criteria • 各式「條件查詢」的做法 • {age: {$gt: 18} } • WHERE http://docs.mongodb.org/manual/core/read-operations/
  • 19. Implement CRUD • MongoDB Shell • MongoDB Script • MongoDB Drivers • Node.js (JavaScript) • Python / Ruby • C / C++ • etc - http://docs.mongodb.org/ecosystem/drivers/
  • 20. MongoDB Script • 使⽤用 JavaScript 語法 • 進⾏行 CRUD 操作 • 撰寫管理功能 • 簡單的 Data Processing (MapReduce)
  • 21. Create One Document // 0001! ! {! var db = connect('localhost/test');! ! db.vipData.save({name: 'jollen', tel: '09384567182'});! ! print('0001-create-one-document finished.')! }
  • 22. List Collection // 0002! ! {! var db = connect('localhost/test');! ! db.vipData.find().forEach(function(user) {! print("User: " + user.name + ", tel: " + user.tel);! });! ! print("Info: 0002-list-collection finished.");! }!
  • 23. Update Document // 0003! ! {! var db = connect('localhost/test');! ! db.vipData.update({name: 'jollen'}, { $set: {name: 'jollenchen'} });! ! print('0004-update-document finished');! }
  • 24. Add News Field // 0004! ! {! var db = connect('localhost/test');! ! db.vipData.find().forEach(function(data) {! data.isActive = true;! db.vipData.save(data);! });! ! print('0004-add-new-field finished');! }
  • 25. Remove Document // 0005! ! {! var db = connect('localhost/test');! ! db.vipData.remove({name: 'jollen'});! ! print('0005-remove-document finished.');! }
  • 27. 基本觀念 • 類似關鍵式資料庫的 Table 設計 • Flexible Schema
  • 28. Schema 設計原則 • When designing data models, always consider the application usage of the data (i.e. queries, updates, and processing of the data) as well as the inherent structure of the data itself. • There are two tools that allow applications to represent these relationships: references and embedded documents. • References • Embedded Data http://docs.mongodb.org/manual/core/data-modeling-introduction/
  • 29. Embedded Document Post Collection _id title content tags Nickname Fullname Mobile Age
  • 30. Reference Model 使⽤用原則 • 亦稱為 Normalized Data Model • 主要⽤用途 • One-to-Many Relations* • Many-to-Many Relations • 主要缺點 • ⽂文件變⼤大時造成 write performance 變差
  • 31. One-To-Many 的情況 #1 {! _id: "joe",! name: "Joe Bookreader”,! address:! {! patron_id: "joe",! street: "123 Fake Street",! city: "Faketon",! state: "MA",! zip: "12345"! }! }! ! {! _id: "joe",! name: "Joe Bookreader"! address:! {! patron_id: "joe",! street: "1 Some Other Street",! city: "Boston",! state: "MA",! zip: “12345"! }! }
  • 33. 關於 Reference Model • 建議使⽤用的 Data Model • Using references between documents • Avoid duplication of data • Provide sufficient read performance advantage
  • 34. Schema Design User Collection _id name email address age Message Collection _id message uid
  • 35. 專案描述 • 將 Microsoft Excel 資料庫,轉換⾄至 NoSQL 的開發任務 • 客⼾戶資料是以 Excel 維護,現在想將客⼾戶資 料「上雲端」,並製作 App 以隨時追蹤或查 詢 • 將客⼾戶資料轉換為 NoSQL 資料庫。以便進 ⾏行 RESTful Web Service 的開發,以及 App 的製作
  • 36. CRUD: Task 1 • 建⽴立 vcard 資料庫 • 新增資料⾄至 vcard.users collections • 資料欄位 • name • phone • email • address • age
  • 37. 提⽰示 • 將 users.xls 匯⼊入 vcard.users collection • 註:users.xls 是程式產⽣生的假資料,⾮非真實 資料
  • 38. CRUD: Task 2 • 新增資料⾄至 vcard.messages collections • 資料欄位 • uid(紀錄 ObjectId) • message(⽂文章內⽂文)
  • 40. 使⽤用 Query Criteria http://docs.mongodb.org/manual/core/crud-introduction/
  • 41. CRUD: Task 3 • 公司想針對 45 歲以下的客⼾戶進⾏行⾏行銷推廣 • 找出 18 歲以上的客⼾戶
  • 42. 使⽤用 Aggregation exports.query = function(req, res) {! ! var model = req.app.db.models.User;! ! ! model! ! .aggregate([! {! ! $project: { _id: 1, name: 1, age: 1 }! },! {! ! $match: {age: {$gt: 45} }! },! {! ! $match: {age: {$lt: 60} }! }])! ! .exec(function(err, users) {! ! ! res.send(users);! ! ! res.end();! ! });! }
  • 43. Mokoversity REST API-Using Node.js and mongoose
  • 46. User Collection 的 Schema // Model name: ‘User’! var userSchema = new mongoose.Schema({! name: { type: String, default: ''},! email: String,! address: String,! age: { type: Number, default: 0 }! }); User Collection name email address age
  • 47. Message Collection 的 Schema // Model name: ‘Message’! var messageSchema = new mongoose.Schema({! uid: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },! message: String! }); Message Collection _id message uid
  • 48. 使⽤用 $in Operator • 興趣有 ‘sport’ 的會員 { interests: { $in: [ 'sport' ] } }
  • 49. Populate model! .find()! .populate('uid')! .exec(function(err, posts) {! res.send(posts);! res.end();! });