Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
MongoDB 101
Nick Jackson
May 07, 2012
Technology
1
93
MongoDB 101
A crash course on MongoDB I gave to attendees at the JISC MRD Hackday organised by DevCSI.
Nick Jackson
May 07, 2012
Tweet
Share
More Decks by Nick Jackson
See All by Nick Jackson
It's all about the data.
jacksonj04
0
59
Development Tools
jacksonj04
0
75
Eating Your Own Dog Food
jacksonj04
0
290
LNCD and The Cloud
jacksonj04
0
97
OAuth 101
jacksonj04
3
320
API Driven Development
jacksonj04
0
190
We Can Haz Ur Datas?!
jacksonj04
0
250
Universal Search at Lincoln
jacksonj04
0
26
Jerome Overview
jacksonj04
0
29
Other Decks in Technology
See All in Technology
Retca Cloud
bau
0
510
Building smarter apps with machine learning, from magic to reality
picardparis
4
3.2k
miisan's career talk
mii3king
0
220
SI企業が「アジャイル推し」になったら 幸せになれますか?/Can SI company be happy if it becomes “Agile stan” ?
chinmo
1
1.2k
Custom GitHub Actions by Java
kazamori
0
290
Security Hub のマルチアカウント 管理・運用をサーバレスでやってみる
ch6noota
0
820
機械学習システムアーキテクチャ入門 #1
asei
3
1.2k
ひとりでも安定して 組織を変える活動を続けていくための ストレスマネジメント
pastelinc
0
850
データエンジニアと作るデータ文化
yuki_saito
4
1.6k
220628 「Google AppSheet」タスク管理アプリをライブ作成 吉積情報伊藤さん
comucal
PRO
0
210
Istio入門
nutslove
15
5k
IoTLT88-NTKanazawa-laundry-dry
yukima0707
0
220
Featured
See All Featured
Writing Fast Ruby
sferik
612
57k
We Have a Design System, Now What?
morganepeng
35
3k
The World Runs on Bad Software
bkeepers
PRO
57
5.3k
Scaling GitHub
holman
451
140k
Design by the Numbers
sachag
271
17k
Ruby is Unlike a Banana
tanoku
91
9.2k
Building Applications with DynamoDB
mza
83
4.7k
Designing Experiences People Love
moore
130
22k
Statistics for Hackers
jakevdp
781
210k
How GitHub (no longer) Works
holman
296
140k
Raft: Consensus for Rubyists
vanstee
126
5.4k
Why You Should Never Use an ORM
jnunemaker
PRO
47
7.6k
Transcript
MongoDB 101
I am... • Nick Jackson • Awesome Developer Dude •
University of Lincoln • @jacksonj04
MongoDB Is... • A NoSQL document database.
Eh?
NoSQL • Is not a specification (unlike SQL). • (Generally)
doesn’t have schemas. • (Generally) works at web-scale. • (Generally) doesn’t do relational integrity.
Document Databases • Store documents. • Don’t store key-value pairs.
• Make building APIs and stuff really easy.
Ye Olde SQL id name email 1 Nick nijackson@lincoln.ac.uk 2
Joss jwinn@lincoln.ac.uk
Ye Olde SQL id name email office building 1 Nick
... 3107 MHT 2 Joss ... 3015 MHT 3 Harry ... NULL MHT
:-(
Documents: Awesome! { name: ‘Nick’, email: ‘nijackson@lincoln.ac.uk’, location: { office:
‘3105’, building: ‘MHT’ } }
Documents: Awesome! { name: ‘Harry’, email: ‘hnewton@lincoln.ac.uk’ }
Documents: Awesome! { name: ‘Joss’, email: ‘jwinn@lincoln.ac.uk’, location: { office:
‘3105’, building: ‘MHT’ }, likes: { music: [‘Folk’, ‘Hip-Hop’], drink: [‘Coffee’, ‘Ale’] } }
Servers Are Easy
On Its Own Mongo App
Replicated Mongo 1 Mongo 2 Mongo 3 App
Sharded App Router 1 Router 2 Mongo S1 Mongo S2
Mongo S3
http://mongodb.org
Inserts <3 JSON > db.people.save({name:'Nick'}) > db.people.save({name:'Joss'}) > db.people.save({name:'Harry'})
Query Be Simple... > db.people.find() { "_id" : ObjectId("4fa...103"), "name"
: "Nick" } { "_id" : ObjectId("4fa...104"), "name" : "Joss" } { "_id" : ObjectId("4fa...105"), "name" : "Harry" }
Query Be Simple... > db.people.find({name:'Nick'}) { "_id" : ObjectId("4fa...103"), "name"
: "Nick" }
Query Be Quick... > db.people.ensureIndex({name:1})
Updates are easy > db.people.update({name:'Nick'},{name:'Nick',likes: ['coffee']}) > db.people.find({name:'Nick'}) { "_id"
: ObjectId("4fa...103"), "name" : "Nick", "likes" : [ "coffee" ] }
Queries are powerful > db.people.update({name:'Joss'},{name:'Joss',likes: ['coffee','folk music']}) > db.people.find({likes:'coffee'}) {
"_id" : ObjectId("4fa...103"), "name" : "Nick", "likes" : [ "coffee" ] } { "_id" : ObjectId("4fa...104"), "name" : "Joss", "likes" : [ "coffee", "folk music" ] }
Deletes are also easy > db.people.remove({name:'Nick'}) > db.people.find() { "_id"
: ObjectId("4fa...104"), "name" : "Joss", "likes" : [ "coffee", "folk music" ] } { "_id" : ObjectId("4fa...105"), "name" : "Harry" }
Cool Things! • Geospatial indexes. db.places.find({loc:{$near:[-2, 53]}}) • JavaScript in
the Mongo shell. • Map/Reduce operations. • Can be used as a filesystem.
Downsides It has a few
It’s not ACID • Set of atomic operators, but no
things like transactions. • No enforced consistency. At all. • No locking, so updates can collide and be lost. • Disk writes are (usually) deferred, so data can be lost in failures.
It’s not ‘Enterprise’ • Your DBAs will find it new
and scary. • You need to un-learn a lot of the SQL mindset. • It’s not seen as ‘proven’, but this is generally rubbish.
Some MongoDB Users • Craigslist • MTV • SourceForge •
Disney • National Archives • HM Government • The Guardian • New York Times • bit.ly • GitHub • Foursquare • http://lncn.eu/fhx5