Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using MongoDB

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
Tweet

More Decks by Dougal MacPherson

Other Decks in Technology

Transcript

  1. 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. 2 Monday, 9 May 2011 Explain scanoutlet - wrote a

    service (powered by MongoDB) for iPhones to consume
  3. Why use a document database? 3 Monday, 9 May 2011

    User defined attributes Schema would have been a mess?
  4. 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?
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. ★ 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
  13. 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
  14. What it allowed us to do 8 Monday, 9 May

    2011 No join tables - for tagging objects Simpler code = more reliable
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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”
  22. Some things to be aware of 11 Monday, 9 May

    2011 As when you get any new cool hammer - everything looks like a nail
  23. 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
  24. 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
  25. 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
  26. 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
  27. Nested Documents 13 Monday, 9 May 2011 We like to

    write tests to exercise our code Callbacks - before/after validation after delete
  28. 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
  29. 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
  30. 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
  31. 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