How to look like a model? MongoDB for Rails apps

360 views

Published on

@muc_rubyshift 11/09/2013

Published in: Technology
  • Be the first to comment

  • Be the first to like this

How to look like a model? MongoDB for Rails apps

  1. 1. Anna Bulenkova @povergo Software Developer @ JetBrains Brains Brains Brains Brains Brains
  2. 2. MongoDB
  3. 3. How to look like a model? a model?
  4. 4. A long time ago in a galaxy far, far away
  5. 5. Wow! It’s schema-free! It’s schema-free!
  6. 6. Say bye-bye to
  7. 7. •Normalization Say bye-bye to
  8. 8. •Normalization •Joins Say bye-bye to
  9. 9. •Normalization •Joins •Design issues Say bye-bye to
  10. 10. •Normalization •Joins •Design issues •Transactions Say bye-bye to
  11. 11. Something wrong?
  12. 12. Document = { key -> value } { key -> value } { key -> value }
  13. 13. Document-oriented != schema-free schema-free schema-free
  14. 14. Collection
  15. 15. BSON
  16. 16. "x16x00x00x00x02hellox 00 x06x00x00x00worldx00x 00"
  17. 17. Outside MongoDB world?
  18. 18. MongoDB •Win/OS X/*nix •JavaScript
  19. 19. user = { name : "Foo" } db.testData.insert(user) db.testData.find() db.testData.find() db.testData.find()
  20. 20. { "_id" : ObjectId("51a7dc7b2cacf40b79990bf7"), "name" : "Foo" } "name" : "Foo" }
  21. 21. •API •Aggregation •Indexes •Replication •Sharding
  22. 22. A little bit of ActiveRecord? ActiveRecord?
  23. 23. Mongoid
  24. 24. $ gem install mongoid
  25. 25. Configuration
  26. 26. Model
  27. 27. Associations
  28. 28. Embedded 1-1
  29. 29. Embedded 1-N
  30. 30. I want my relationship back!
  31. 31. Referenced 1-1
  32. 32. Referenced 1-N
  33. 33. Referenced N-N
  34. 34. # The band document. { "_id" : ObjectId("4d3ed089fb60ab534684b7e9"), "tag_ids" : [ ObjectId("4d3ed089fb60ab534684b7f2") ] } # The tag document. { "_id" : ObjectId("4d3ed089fb60ab534684b7f2"), "band_ids" : [ ObjectId("4d3ed089fb60ab534684b7e9") ] } } } } } } } } } } } } } }
  35. 35. $gem install mongoid_rails_migrations
  36. 36. It’s magical...
  37. 37. What a twist!
  38. 38. Where the hell are transactions?
  39. 39. 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.
  40. 40. limit 16MB
  41. 41. Global write lock 2.0pre 2.0pre
  42. 42. DB level lock 2.2 2.2
  43. 43. No joins -> Many queries Many queries Many queries
  44. 44. Too many queries? -> Redesign Redesign Redesign
  45. 45. Indeed schemaless?
  46. 46. Journaling 100ms 100ms
  47. 47. Data loss after replication replication replication
  48. 48. Sharding delay
  49. 49. Unencrypted traffic
  50. 50. 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
  51. 51. It’s supported in RubyMine Mine
  52. 52. Any questions?
  53. 53. Thank you!

×