Share
Embed
Using MongoDB
Presentation to Melbourne MongoDB users group on why we're using MongoDB on our most recent project at jTribe
Dougal MacPherson
May 09, 2011
Transcript
32 slides
-
and why we are using it in one of our
applications MongoDB 1 Monday, 9 May 2011 Mongo is a NoSQL database - document database Who is using MongoDB a project now? Fourqusare is using it - so (if you’re a hipster) you’re using it now Our app is written in Ruby on Rails Examples as based on our experience with MongoDB - Your milage may vary -
2 Monday, 9 May 2011 Explain scanoutlet - wrote a
service (powered by MongoDB) for iPhones to consume -
Why use a document database? 3 Monday, 9 May 2011
User defined attributes Schema would have been a mess? -
Why use a document database? Application needed to support schema-less
data 3 Monday, 9 May 2011 User defined attributes Schema would have been a mess? -
Why MongoDB? 4 Monday, 9 May 2011 Others feel a
bit too new - unfamiliar Felt it would take too long to get up to speed Or I would need to study database theory for months -
Why MongoDB? Has the features that is a mix of
new and interesting so I’m excited about it… 4 Monday, 9 May 2011 Others feel a bit too new - unfamiliar Felt it would take too long to get up to speed Or I would need to study database theory for months -
Why MongoDB? Has the features that is a mix of
new and interesting so I’m excited about it… as well as features that I’m familiar with so it’s not too different 4 Monday, 9 May 2011 Others feel a bit too new - unfamiliar Felt it would take too long to get up to speed Or I would need to study database theory for months -
As you’re going to need to convince some people first
5 Monday, 9 May 2011 A lot is to be said for getting up to speed quickly, and enjoying it on the way After all this is what made Rails popular at first -
Yourself As you’re going to need to convince some people
first 5 Monday, 9 May 2011 A lot is to be said for getting up to speed quickly, and enjoying it on the way After all this is what made Rails popular at first -
Yourself Your boss As you’re going to need to convince
some people first 5 Monday, 9 May 2011 A lot is to be said for getting up to speed quickly, and enjoying it on the way After all this is what made Rails popular at first -
Yourself Your boss The client As you’re going to need
to convince some people first 5 Monday, 9 May 2011 A lot is to be said for getting up to speed quickly, and enjoying it on the way After all this is what made Rails popular at first -
★ Documentation is well written ★ and there is a
lot of it ★ Language support is good 6 Monday, 9 May 2011 Other NoSQL have poor documentation - or tool support is minimal OK once you’re experienced - but make the learning curve steeper -
Other much bigger companies are using it 7 Monday, 9
May 2011 “If they’re using it - it must be ok” - spread the risk/blame Foursquare main app Gilt for real time tracking -
What it allowed us to do 8 Monday, 9 May
2011 No join tables - for tagging objects Simpler code = more reliable -
What it allowed us to do Store data in a
structure which matches the logic the application 8 Monday, 9 May 2011 No join tables - for tagging objects Simpler code = more reliable -
What it allowed us to do Store data in a
structure which matches the logic the application Application code is simpler easier to read 8 Monday, 9 May 2011 No join tables - for tagging objects Simpler code = more reliable -
Our schema may have looked like this… 9 Monday, 9
May 2011 This is what the RDBMS schema would have looked look Complicated - Confusing (the new guy isn’t going to understand)- Slow lots of code == lots of bugs -
Variations Images Tag Products Categories Our schema may have looked
like this… 9 Monday, 9 May 2011 This is what the RDBMS schema would have looked look Complicated - Confusing (the new guy isn’t going to understand)- Slow lots of code == lots of bugs -
Variations Images Tag Products Categories Join table Join table Join
table Join table Join table Join table Our schema may have looked like this… 9 Monday, 9 May 2011 This is what the RDBMS schema would have looked look Complicated - Confusing (the new guy isn’t going to understand)- Slow lots of code == lots of bugs -
Variations Images Tag Products Categories Join table Join table Join
table Join table Join table Join table Our schema may have looked like this… 9 Monday, 9 May 2011 This is what the RDBMS schema would have looked look Complicated - Confusing (the new guy isn’t going to understand)- Slow lots of code == lots of bugs -
Products Products Products Products id id 4567abs334 4567abs334 name name
Fancy cheese Fancy cheese description description This is my favourite… This is my favourite… categories categories [ food, cheese, blue ] [ food, cheese, blue ] tags tags [ tasty, happiness ] [ tasty, happiness ] variations ▼ variations ▼ barcode 12340028 sku 12345679 images [ brie.jpg ] smell socks size large price $22.50 Instead our schema looks like this 10 Monday, 9 May 2011 Categories as an array - easy Query on array “contains” “contains any” “contains all” “contains at location” -
Some things to be aware of 11 Monday, 9 May
2011 As when you get any new cool hammer - everything looks like a nail -
Some things to be aware of As sometimes the magic
runs out 11 Monday, 9 May 2011 As when you get any new cool hammer - everything looks like a nail -
Your application has schema 12 Monday, 9 May 2011 Legacy
documents may not have attributes that your code expects This bit us - fortunately is was early in the project -
Your application has schema But your database doesn’t 12 Monday,
9 May 2011 Legacy documents may not have attributes that your code expects This bit us - fortunately is was early in the project -
Your application has schema But your database doesn’t You should
still treat schema changes with caution/respect 12 Monday, 9 May 2011 Legacy documents may not have attributes that your code expects This bit us - fortunately is was early in the project -
Nested Documents 13 Monday, 9 May 2011 We like to
write tests to exercise our code Callbacks - before/after validation after delete -
Nested Documents Like any magic it’s best to use with
some caution 13 Monday, 9 May 2011 We like to write tests to exercise our code Callbacks - before/after validation after delete -
Nested Documents Like any magic it’s best to use with
some caution Harder to test in isolation 13 Monday, 9 May 2011 We like to write tests to exercise our code Callbacks - before/after validation after delete -
Nested Documents Like any magic it’s best to use with
some caution Harder to test in isolation Model callbacks may not work as you’d expect 13 Monday, 9 May 2011 We like to write tests to exercise our code Callbacks - before/after validation after delete -
Nested Documents Like any magic it’s best to use with
some caution Harder to test in isolation Model callbacks may not work as you’d expect Limit the number of embedded docs 13 Monday, 9 May 2011 We like to write tests to exercise our code Callbacks - before/after validation after delete