Rails + mongo db

633 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
633
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rails + mongo db

  1. 1. Rails + MongoDB = <3 Sérgio Santos @sdsantos Improve Coimbra
  2. 2. Introduction / Disclamer
  3. 3. Bundlr MongoDB stats MongoDB from the start ~ 3½ years of development ~ 6 GB of data ~ 6 million documents Cloud hosted on MongoHQ
  4. 4. MongoDB 101
  5. 5. Documents
  6. 6. Collections
  7. 7. References
  8. 8. Embeds
  9. 9. Rails MongoDB ORMs
  10. 10. Mongoid vs MongoMapper
  11. 11. Mongoid
  12. 12. Models class Person include Mongoid::Document end person = Person.new person[:name] = 'Sérgio' person[:age] = 26 person.save
  13. 13. Models class Person include Mongoid::Document field :name, type: String field :age, type: Integer end person = Person.new person.name = 'Sérgio' person.age = 26 person.save
  14. 14. Persistence person = Person.create(name: 'Sérgio', age: 26) person.update_attributes(name: 'Sérgio Santos') person.touch person.delete person.destroy person.rename(:name, :first_name)
  15. 15. Querying person = Person.find("4baa56f1230048567300485c") people = Person.where(age: 18) people = Person.where(name: 'Sérgio').not(age: 26) Person.count Person.all.avg(:age) -- INSERT MAP/REDUCE CLEVER EXAMPLE HERE --
  16. 16. References class Band include Mongoid::Document has_many :members end class Member include Mongoid::Document field :name, type: String belongs_to :band end
  17. 17. References # The parent band document. { "_id" : ObjectId("4d3ed089fb60ab534684b7e9") } # The child member document. { "_id" : ObjectId("4d3ed089fb60ab534684b7f1"), "name" : "Matt Berninger" "band_id" : ObjectId("4d3ed089fb60ab534684b7e9") }
  18. 18. Embeds class Band include Mongoid::Document embeds_many :albums end class Album include Mongoid::Document field :name, type: String embedded_in :band end
  19. 19. Embeds { "_id" : ObjectId("4d3ed089fb60ab534684b7e9"), "albums" : [ { "_id" : ObjectId("4d3ed089fb60ab534684b7e0"), "name" : "Boxer", } ] }
  20. 20. Extras identity map & cache paranoia versioning timestamps geo full text search
  21. 21. Cloud Hosting
  22. 22. Wrapping up…
  23. 23. Rails + MongoDB = <3 Sérgio Santos @sdsantos me@sergiosantos.info We’re hiring! nourishcare.co.uk/careers/

×