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

How to look like a model? MongoDB for Rails apps

How to look like a model? MongoDB for Rails apps

at rubyshift_muc

F14a1fcb0bd63f3d1a999844fd32a263?s=128

Anna Bulenkova

September 10, 2013
Tweet

Transcript

  1. Anna Bulenkova @povergo Software Developer @ JetBrains Friday, October 25,

    13
  2. MongoDB Friday, October 25, 13

  3. Friday, October 25, 13

  4. How to look like a model? Friday, October 25, 13

  5. A long time ago in a galaxy far, far away

    Friday, October 25, 13
  6. Friday, October 25, 13

  7. Friday, October 25, 13

  8. Wow! It’s schema-free! Friday, October 25, 13

  9. Say bye-bye to Friday, October 25, 13

  10. •Normalization Say bye-bye to Friday, October 25, 13

  11. •Normalization •Joins Say bye-bye to Friday, October 25, 13

  12. •Normalization •Joins •Design issues Say bye-bye to Friday, October 25,

    13
  13. •Normalization •Joins •Design issues •Transactions Say bye-bye to Friday, October

    25, 13
  14. Something wrong? Friday, October 25, 13

  15. Document = { key -> value } Friday, October 25,

    13
  16. Document-oriented != schema-free Friday, October 25, 13

  17. Friday, October 25, 13

  18. Collection Friday, October 25, 13

  19. BSON Friday, October 25, 13

  20. {"hello": "world"} "\x16\x00\x00\x00\x02hello \x00 \x06\x00\x00\x00world \x00\x00" Friday, October 25, 13

  21. Outside MongoDB world? Friday, October 25, 13

  22. MongoDB •Win/OS X/*nix •JavaScript Friday, October 25, 13

  23. user = { name : "Foo" } db.testData.insert(user) db.testData.find() Friday,

    October 25, 13
  24. { "_id" : ObjectId("51a7dc7b2cacf40b79990bf7"), "name" : "Foo" } Friday, October

    25, 13
  25. Friday, October 25, 13

  26. •API •Aggregation •Indexes •Replication •Sharding Friday, October 25, 13

  27. A little bit of ActiveRecord? Friday, October 25, 13

  28. Mongoid Friday, October 25, 13

  29. $ gem install mongoid Friday, October 25, 13

  30. Configuration Friday, October 25, 13

  31. Model Friday, October 25, 13

  32. Associations Friday, October 25, 13

  33. Embedded 1-1 Friday, October 25, 13

  34. Embedded 1-N Friday, October 25, 13

  35. I want my relationship back! Friday, October 25, 13

  36. Referenced 1-1 Friday, October 25, 13

  37. Referenced 1-N Friday, October 25, 13

  38. Referenced N-N Friday, October 25, 13

  39. # The band document. { "_id" : ObjectId("4d3ed089fb60ab534684b7e9"), "tag_ids" :

    [ ObjectId("4d3ed089fb60ab534684b7f2") ] } # The tag document. { "_id" : ObjectId("4d3ed089fb60ab534684b7f2"), "band_ids" : [ ObjectId("4d3ed089fb60ab534684b7e9") ] } Friday, October 25, 13
  40. $gem install mongoid_rails_migrations Friday, October 25, 13

  41. Friday, October 25, 13

  42. It’s magical... Friday, October 25, 13

  43. What a twist! Friday, October 25, 13

  44. Where the hell are transactions? Friday, October 25, 13

  45. MongoDB does not have support for traditional locking or complex

    transactions with rollback. MongoDB aims to be lightweight, fast, and predictable in its performance. This is similar to the MySQL MyISAM autocommit model. By keeping transaction support extremely simple, MongoDB can provide greater performance especially for partitioned or replicated systems with a number of database server processes. Friday, October 25, 13
  46. Document size limit 16MB Friday, October 25, 13

  47. Global write lock 2.0pre Friday, October 25, 13

  48. DB level lock 2.2 Friday, October 25, 13

  49. No joins -> Many queries Friday, October 25, 13

  50. Too many queries? -> Redesign Friday, October 25, 13

  51. Indeed schemaless? Friday, October 25, 13

  52. Journaling 100ms Friday, October 25, 13

  53. Data loss after replication Friday, October 25, 13

  54. Sharding delay Friday, October 25, 13

  55. Unencrypted traffic Friday, October 25, 13

  56. Side effects may include... Problems working on 32-bit, large data

    storage problems, write falures, no error value return, sophicticated schema design, limited update operation, case sensitive queries, type sensitive fields, write locks, replica sets restrictions, unexpected data loss, sharding size limitations, no transactions, nausea, going back to RDBMS Friday, October 25, 13
  57. It’s supported in RubyMine Friday, October 25, 13

  58. Friday, October 25, 13

  59. Friday, October 25, 13

  60. Friday, October 25, 13

  61. Any questions? Friday, October 25, 13

  62. Thank you! Friday, October 25, 13