Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MongoDB and Mongoose Tutorial
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
andikan
May 08, 2014
Programming
1.4k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
MongoDB and Mongoose Tutorial
2014/05/08 @ NTU CCSP
https://github.com/NTU-CCSP/mongoose-tutorial
andikan
May 08, 2014
More Decks by andikan
See All by andikan
Deployment and Others Tutorial
andikan
1
680
Other Decks in Programming
See All in Programming
数百円から始めるRuby電子工作
tarosay
0
140
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
580
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
290
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
460
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
220
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
150
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
140
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
1
250
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
260
the container ship “Apple Silicon”@WWDC26 Recap -Japan-\(region).swift
shingangan
0
110
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
150
Featured
See All Featured
How to Ace a Technical Interview
jacobian
281
24k
How GitHub (no longer) Works
holman
316
150k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
830
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
240
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
360
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
The untapped power of vector embeddings
frankvandijk
2
1.8k
KATA
mclloyd
PRO
35
15k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
360
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Building Applications with DynamoDB
mza
96
7.2k
Skip the Path - Find Your Career Trail
mkilby
1
180
Transcript
Cloud Computing-Based Service Design and Programming Andy Kuo @andikan 1
DB = DataBase (n.) 資料庫 A database is an organized
collection of data. 2
3
Hello DB! 4
SQL Relational Database 5
NoSQL http://nosql-database.org/ Not Only SQL 6
Volume • Velocity • Variety 7
Key / Value Column Graph Document 8
MongoDB scalable, high-performance, open source NoSQL database • document store
• full index support • replication • querying • map / reduce 9
MongoDB implemented in C++ drivers are available in many language
http://docs.mongodb.org/manual/applications/drivers/ MongoDB Drivers and Client Libraries 10
BSON Binary JSON BSON = JSON + a few additions
• ObjectID • Timestamp • Date 11
MongoDB Terminology Relational DBs MongoDB database database table collection row
(tuple) document (BSON) column field index index primary key _id foreign key 12
Collection Document 13
Download : http://www.mongodb.org/downloads Installation : http://docs.mongodb.org/manual/installation/ Getting Started 14
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/ https://speakerdeck.com/xpsteven/ntu-ccsp-2012fall-node-dot-js-number-3-mongoose Install MongoDB on Windows 15
mongod The primary daemon process for the MongoDB system It
handles data requests, manages data format, and performs background management operations 16
Default dbpath /data/db Can use your custom directory 17
Listen on localhost : 27017 18
admin web console localhost : 28017 19
Connect to mongod By default, mongo looking for a database
server listening on port 27017 on the localhost 20
Welcome to the MongoDB shell Session will use the test
database by default Access with the Javascript Language 21
http://try.mongodb.org/ 22
Name of the current database Display the list of databases
Switch to a new database named cooldb 23
Insert a document into a collection 24
Traverse documents in a collection 25
Methods to create documents 26
Methods to update documents 27
Methods to delete documents 28
Methods to query documents 29
Methods to query documents Query Operators Comparison: $gt, $gte, $in,
$lt, $lte, $ne, $nin Logical: $or, $and, $not, $nor Array: $all, $size, $eleMatch More: http://docs.mongodb.org/manual/reference/operator/query/ 30
Create / Read / Update / Delete CRUD http://docs.mongodb.org/manual/ More
about MongoDB 31
http://docs.mongodb.org/ecosystem/tools/administration-interfaces/ Admin UIs MongoHub RoboMongo Mac OS X Cross-platform 32
ORM Object-relational Mapper ( Relational DB ) ODM Object-document Mapper
( MongoDB ) validations, associations, and other high-level data modeling functions 33
Mongoose Officially supported ODM for Node.js Advanced schema-based features Object
life-cycle management Mongoose http://mongoosejs.com/ 34
Install Mongoose Or install in your express project directory 35
Create Schema - models/user.js Schema Types - String - Number
- Date - Buffer - Boolean - Mixed - ObjectId - Array 36
Connect DB - db.js 37
Require db.js - app.js 38
Routes - app.js 39
Require model - routes/user.js 40
Postman Chrome extension A powerful HTTP Client to test web
services http://www.getpostman.com/ 41
Get all users - routes/user.js GET /users 42
Create a user - routes/user.js POST /users 43
Show a user - routes/user.js GET /users/:id 44
Update a user - routes/user.js POST /users/:id 45
Delete a user - routes/user.js Delete /users/:id 46
https://github.com/NTU-CCSP/mongoose-tutorial Sample Code 47
The versionKey is a property set on each document when
first created by Mongoose. This keys value contains the internal revision of the document. __v http://mongoosejs.com/docs/guide.html#versionKey 48
Query with Mongoose 49
Query with Mongoose 50
Population Pseudo-joins Reference to documents in other collections 51
Population - Schema 52
Population - Saving refs 53
Population - Query 54
Population - Refs to children 55
Population - Query 56
page.fans ? CCSP Facebook Page https://www.facebook.com/ntu.ccsp 57
Mongoose Plugins Re-use schema functionality in your own project -
Auto increment https://github.com/codetunnel/mongoose-auto-increment - Timestamp https://github.com/drudge/mongoose-timestamp 58
Callback Hell - Promises - Async.js https://github.com/caolan/async - Step.js https://github.com/creationix/step
http://callbackhell.com/ 59
Cloud Computing-Based Service Design and Programming Andy Kuo @andikan Thanks
60