Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
NTU CCSP 2012Fall - Node.js #3 - Mongoose
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Steven Su
October 31, 2012
Programming
780
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
NTU CCSP 2012Fall - Node.js #3 - Mongoose
Data Layer / Mongodb / Mongoose
Steven Su
October 31, 2012
More Decks by Steven Su
See All by Steven Su
JSDC.TW 2013 Node.js佈署心得
xpsteven
14
1.3k
NTU CCSP 2012Fall - Mobile Web入門 回首網頁開發
xpsteven
3
370
NTU CCSP 2012Fall - Facebook
xpsteven
1
230
NTU CCSP 2012Fall - Node.js #2.1 - Simple File Host Service
xpsteven
2
470
NTU CCSP 2012Fall - Node.js #2 - express.js
xpsteven
3
590
Y! Open Hack 2012 Taiwan
xpsteven
0
250
NTU CCSP 2012Fall - Node.js #2 - Advanced Javascript and Node.js
xpsteven
1
570
Other Decks in Programming
See All in Programming
R8 の設定見直しでアプリサイズ削減
andpad
0
220
最近”作らせてる” ローカルAIアプリの話
akit37
0
470
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
500
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
430
The Rails Doctrine Decade
koic
2
590
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
contenteditable と日本語入力に向き合う
colorful12
0
200
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
270
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
Featured
See All Featured
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
800
Ethics towards AI in product and experience design
skipperchong
2
430
RailsConf 2023
tenderlove
30
1.6k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
940
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
The SEO Collaboration Effect
kristinabergwall1
1
590
Optimizing for Happiness
mojombo
378
71k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
Fireside Chat
paigeccino
43
4.1k
sira's awesome portfolio website redesign presentation
elsirapls
0
450
Transcript
資料層:Mongoose NTU CCSP 2012Fall
目標 • 安裝mongodb • 使用mongo shell • 簡易CRUD
環境 • Windows 7 • Sublime Text 2 • Node.js
0.8.x • Express.js 3.0 • Mongoose.js
MONGODB INSTALL
Step 0: 下載mongodb
Step 0: 下載mongodb
Step 1: 解壓縮移動到C 並命名為mongodb
Step 2: 設定環境
Step 3: 啟動mongod
Step 4: 進入mongo shell
MONGO SHELL
MongoDB • 是一種NoSQL • 不需要資料綱要(Schema-Free) • 允許巢狀資料 • 沒有JOIN 沒有TRANS
• 簡單說就是一個存放JSON的資料庫 所以才 會跟Node.js很合
MongoDB練習 • http://try.mongodb.org/
FIRST LOOK OF MONGOOSE
Step -1: 請先安裝mongoose npm install mongoose -g
Step 0: 產生綱要 1. 產生schema 2. 產生model instance.save(fn(err){}) 儲存 Model.find()
搜尋
Step 0: 產生綱要
Step 1: 更新與刪除 • Model.remove() 刪除所有文件 • instance.remove() 刪除一個文件
Step 2: 綱要進階 • 常用type String, Number, Date, ObjectId •
Array用法 • Embed Docs => Array嵌入物件
CRUD BY EXPRESS+MONGOOSE
Step 0: 建立express專案
Step 1: 修改package.json
Step 2: 安裝套件
Step3: 編輯models/User.js
Step 3: 編輯 app.js • mongoose.connect和 mongoose.createConnection是不 同的 • 前者是模組等級
後者是獨立連線 • 沒有指明連線的model會嘗試使用 並等待模組等級連線建立
Step 4: Create • 編輯route/user.js • 注意callback的例外
Step 4: Create • 編輯view/index.ejs
Step 4.5: 來試試看吧
Step 5: Read • Read包含兩種 • 讀取集合 • 讀取單一物件
Step 6: Update
Step 6: Update • Callback hell很痛苦 • 銀幕在寬都不夠
Step 8: step.js解決cb hell • 解決callback hell • Err可以很帥氣的throw
遺珠之憾 • Population http://mongoosejs.com/docs/populate.html • Middleware http://mongoosejs.com/docs/middleware.html • Advanced Query
http://mongoosejs.com/docs/queries.html • SQL to Mongo mapping http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Map ping+Chart • Step.js https://github.com/creationix/step