MongoDB and Ruby                       domain modeling with MongoMapperWednesday, 23 January 13
Volker Pacher                           senior developer @shutl                                    @vpacher               ...
Wednesday, 23 January 13
Wednesday, 23 January 13
• SaaS platformWednesday, 23 January 13
• SaaS platform      • we provide an API for carriers and merchantsWednesday, 23 January 13
• SaaS platform      • we provide an API for carriers and merchants      • customers can chose between a delivery either:W...
• SaaS platform      • we provide an API for carriers and merchants      • customers can chose between a delivery either: ...
• SaaS platform      • we provide an API for carriers and merchants      • customers can chose between a delivery either: ...
• SaaS platform      • we provide an API for carriers and merchants      • customers can chose between a delivery either: ...
• SaaS platform      • we provide an API for carriers and merchants      • customers can chose between a delivery either: ...
• SaaS platform      • we provide an API for carriers and merchants      • customers can chose between a delivery either: ...
• SaaS platform      • we provide an API for carriers and merchants      • customers can chose between a delivery either: ...
• SaaS platform      • we provide an API for carriers and merchants      • customers can chose between a delivery either: ...
Wednesday, 23 January 13
Shutl Main Red:         Shutl Accent Red:                                                                   Pantone 485 C ...
Shutl Main Red:         Shutl Accent Red:                                                                   Pantone 485 C ...
Shutl Main Red:         Shutl Accent Red:                                                                   Pantone 485 C ...
Shutl Main Red:         Shutl Accent Red:                                                                   Pantone 485 C ...
Shutl Main Red:         Shutl Accent Red:                                                                   Pantone 485 C ...
Shutl Main Red:         Shutl Accent Red:                                                                   Pantone 485 C ...
Shutl Main Red:         Shutl Accent Red:                                                                   Pantone 485 C ...
MongoMapperWednesday, 23 January 13
MongoMapper         • http://mongomapper.com/Wednesday, 23 January 13
MongoMapper         • http://mongomapper.com/         • written by John Nunemaker (github)Wednesday, 23 January 13
MongoMapper         • http://mongomapper.com/         • written by John Nunemaker (github)         • code at https://githu...
Alternatives:Wednesday, 23 January 13
Alternatives:         • Mongoid: http://mongoid.org/en/mongoid/index.htmlWednesday, 23 January 13
Alternatives:         • Mongoid: http://mongoid.org/en/mongoid/index.html         • MongoODM: https://github.com/carlospar...
Alternatives:         • Mongoid: http://mongoid.org/en/mongoid/index.html         • MongoODM: https://github.com/carlospar...
installation:Wednesday, 23 January 13
installation:                           • in your gemfile:Wednesday, 23 January 13
installation:                           • in your gemfile:                           • gem ‘mongo_mapper’Wednesday, 23 Janu...
installation:                           • in your gemfile:                           • gem ‘mongo_mapper’                  ...
db initialization:include MongoMapperMongoMapper.connection =Mongo::Connection.new(localhost, 27017)MongoMapper.database =...
First document:                class User                  include MongoMapper::Document                       key :name, ...
embedded document:        class Note          include MongoMapper::EmbeddedDocument          key :text, String        endW...
create a document:    user = User.new(name:James Chester)    user.notes.build(text:a note)    user.save!    User.where(:na...
What is an embedded document?Wednesday, 23 January 13
What is an embedded document?          • a document has it’s own collection in the database (table)Wednesday, 23 January 13
What is an embedded document?          • a document has it’s own collection in the database (table)          • an embedded...
What is an embedded document?          • a document has it’s own collection in the database (table)          • an embedded...
What is an embedded document?          • a document has it’s own collection in the database (table)          • an embedded...
When to use embedded and when not toWednesday, 23 January 13
When to use embedded and when not to          • only embed when the document will be shown in the          context of the ...
When to use embedded and when not to          • only embed when the document will be shown in the          context of the ...
When to use embedded and when not to          • only embed when the document will be shown in the          context of the ...
{       id:     50fd8a786bcb608e1c000002,      name: James Chester,      address: {},      notes:         [           { id...
types:Wednesday, 23 January 13
types:  • mongomapper supports the ruby data types:       Integer, Float, String, Array, Hash, Object, Time, NilClassWedne...
types:  • mongomapper supports the ruby data types:       Integer, Float, String, Array, Hash, Object, Time, NilClass  • a...
types:  • mongomapper supports the ruby data types:       Integer, Float, String, Array, Hash, Object, Time, NilClass  • a...
custom types:    class UpcaseString      def self.to_mongo(value)        value.nil? ? nil : value.to_s.upcase      end    ...
finding a document:Wednesday, 23 January 13
finding a document:  • find by id:             User.find(‘50fd8a726bcb608e1c000001’)Wednesday, 23 January 13
finding a document:  • find by id: User.find(‘50fd8a726bcb608e1c000001’)  • find by field: User.first(:name => James)Wednesday...
finding a document:  • find by id: User.find(‘50fd8a726bcb608e1c000001’)  • find by field: User.first(:name => James)  • query...
finding a document:  • find by id: User.find(‘50fd8a726bcb608e1c000001’)  • find by field: User.first(:name => James)  • query...
dynamic querying:Wednesday, 23 January 13
dynamic querying:  • MongoMapper uses plucky to the allow the construction of query  proxy objects that only get executed ...
dynamic querying:  • MongoMapper uses plucky to the allow the construction of query  proxy objects that only get executed ...
dynamic querying:  • MongoMapper uses plucky to the allow the construction of query  proxy objects that only get executed ...
dynamic querying:  • MongoMapper uses plucky to the allow the construction of query  proxy objects that only get executed ...
operators:Wednesday, 23 January 13
operators:   • all mongodb operators can be used directly in mongomapperWednesday, 23 January 13
operators:   • all mongodb operators can be used directly in mongomapper   • http://docs.mongodb.org/manual/reference/oper...
operators:   • all mongodb operators can be used directly in mongomapper   • http://docs.mongodb.org/manual/reference/oper...
operators:   • all mongodb operators can be used directly in mongomapper   • http://docs.mongodb.org/manual/reference/oper...
operators:   • all mongodb operators can be used directly in mongomapper   • http://docs.mongodb.org/manual/reference/oper...
destroy/delete:Wednesday, 23 January 13
destroy/delete:                  • destroy triggers callbacks, delete does notWednesday, 23 January 13
destroy/delete:                  • destroy triggers callbacks, delete does not                  • User.destroy(‘50fd8a786b...
destroy/delete:                  • destroy triggers callbacks, delete does not                  • User.destroy(‘50fd8a786b...
destroy/delete:                  • destroy triggers callbacks, delete does not                  • User.destroy(‘50fd8a786b...
validations:                    MongoMapper uses Rails ActiveModel:Validations    http://api.rubyonrails.org/classes/Activ...
include MongoMapper::Document          key :name, String, required: true          key :age, Integer          validates_num...
shorthands available:                           :required – Boolean                           :unique – Boolean           ...
indexes:Wednesday, 23 January 13
indexes: • put indexes into the initializerWednesday, 23 January 13
indexes: • put indexes into the initializer            • index on single field:                           User.ensure_index...
indexes: • put indexes into the initializer            • index on single field:                            User.ensure_inde...
indexes: • put indexes into the initializer            • index on single field:                            User.ensure_inde...
indexes: • put indexes into the initializer            • index on single field:                            User.ensure_inde...
indexes: • put indexes into the initializer            • index on single field:                            User.ensure_inde...
using the decorator/presenter pattern for schemaless dbs                                                  decorator       ...
Any questions?  Volker Pacher  volker@shutl.co.uk                        shutl.co.uk  @vpacher                            ...
Upcoming SlideShare
Loading in …5
×

Shutl mongob usergroup talk jan 2013

321
-1

Published on

Introduction into MongoDB and Ruby at the January 2013 MongoDB user group, London

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
321
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Shutl mongob usergroup talk jan 2013

  1. 1. MongoDB and Ruby domain modeling with MongoMapperWednesday, 23 January 13
  2. 2. Volker Pacher senior developer @shutl @vpacher http://github.com/vpacherWednesday, 23 January 13
  3. 3. Wednesday, 23 January 13
  4. 4. Wednesday, 23 January 13
  5. 5. • SaaS platformWednesday, 23 January 13
  6. 6. • SaaS platform • we provide an API for carriers and merchantsWednesday, 23 January 13
  7. 7. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either:Wednesday, 23 January 13
  8. 8. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either: within 90 minutes of purchaseWednesday, 23 January 13
  9. 9. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either: within 90 minutes of purchase or a 1 hour window of their choiceWednesday, 23 January 13
  10. 10. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either: within 90 minutes of purchase or a 1 hour window of their choice (same day or any day)Wednesday, 23 January 13
  11. 11. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either: within 90 minutes of purchase or a 1 hour window of their choice (same day or any day) • fastest delivery to date 14:00 minWednesday, 23 January 13
  12. 12. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either: within 90 minutes of purchase or a 1 hour window of their choice (same day or any day) • fastest delivery to date 14:00 min • customers: Argos, Maplins, DrEd.com ...Wednesday, 23 January 13
  13. 13. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either: within 90 minutes of purchase or a 1 hour window of their choice (same day or any day) • fastest delivery to date 14:00 min • customers: Argos, Maplins, DrEd.com ... • json apiWednesday, 23 January 13
  14. 14. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either: within 90 minutes of purchase or a 1 hour window of their choice (same day or any day) • fastest delivery to date 14:00 min • customers: Argos, Maplins, DrEd.com ... • json api •built with sinatra, jruby, neo4j and mongodbWednesday, 23 January 13
  15. 15. Wednesday, 23 January 13
  16. 16. Shutl Main Red: Shutl Accent Red: Pantone 485 C Pantone 484 C Let’s get going: C0 M100 Y99 K4 C0 M100 Y99 K4 R208 G31 B40 R208 G31 B40red on white HEX D01F28 HEX D01F28 red on lighter tones Shutl Black: Shutl Accent Grey: Pantone BLACK Pantone BLACK C0 M0 Y0 K0100 C0 M0 Y0 K70 @ 70% Please note:Black on white Reverse (white) on darker tones The black logo should never appear on in any ‘dark’ colour background. 5 Branding GuidelinesWednesday, 23 January 13
  17. 17. Shutl Main Red: Shutl Accent Red: Pantone 485 C Pantone 484 C Let’s get going: C0 M100 Y99 K4 C0 M100 Y99 K4 R208 G31 B40 R208 G31 B40red on white HEX D01F28 HEX D01F28 red on lighter tones Shutl Black: Shutl Accent Grey: Pantone BLACK Pantone BLACK • install mongodb with brew install mongodb C0 M0 Y0 K0100 C0 M0 Y0 K70 @ 70% Please note:Black on white Reverse (white) on darker tones The black logo should never appear on in any ‘dark’ colour background. 5 Branding GuidelinesWednesday, 23 January 13
  18. 18. Shutl Main Red: Shutl Accent Red: Pantone 485 C Pantone 484 C Let’s get going: C0 M100 Y99 K4 C0 M100 Y99 K4 R208 G31 B40 R208 G31 B40red on white HEX D01F28 HEX D01F28 red on lighter tones Shutl Black: Shutl Accent Grey: Pantone BLACK Pantone BLACK • install mongodb with brew install mongodb C0 M0 Y0 K0100 C0 M0 Y0 K70 @ 70% Please note:Black on white Reverse (white) on darker tones The black logo should never appear on in any ‘dark’ colour • in your gemfile: background. 5 Branding GuidelinesWednesday, 23 January 13
  19. 19. Shutl Main Red: Shutl Accent Red: Pantone 485 C Pantone 484 C Let’s get going: C0 M100 Y99 K4 C0 M100 Y99 K4 R208 G31 B40 R208 G31 B40red on white HEX D01F28 HEX D01F28 red on lighter tones Shutl Black: Shutl Accent Grey: Pantone BLACK Pantone BLACK • install mongodb with brew install mongodb C0 M0 Y0 K0100 C0 M0 Y0 K70 @ 70% Please note:Black on white Reverse (white) on darker tones The black logo should never appear on in any ‘dark’ colour • in your gemfile: background. 5 Branding Guidelines • gem ‘mongo’Wednesday, 23 January 13
  20. 20. Shutl Main Red: Shutl Accent Red: Pantone 485 C Pantone 484 C Let’s get going: C0 M100 Y99 K4 C0 M100 Y99 K4 R208 G31 B40 R208 G31 B40red on white HEX D01F28 HEX D01F28 red on lighter tones Shutl Black: Shutl Accent Grey: Pantone BLACK Pantone BLACK • install mongodb with brew install mongodb C0 M0 Y0 K0100 C0 M0 Y0 K70 @ 70% Please note:Black on white Reverse (white) on darker tones The black logo should never appear on in any ‘dark’ colour • in your gemfile: background. 5 Branding Guidelines • gem ‘mongo’ • gem ‘bson’Wednesday, 23 January 13
  21. 21. Shutl Main Red: Shutl Accent Red: Pantone 485 C Pantone 484 C Let’s get going: C0 M100 Y99 K4 C0 M100 Y99 K4 R208 G31 B40 R208 G31 B40red on white HEX D01F28 HEX D01F28 red on lighter tones Shutl Black: Shutl Accent Grey: Pantone BLACK Pantone BLACK • install mongodb with brew install mongodb C0 M0 Y0 K0100 C0 M0 Y0 K70 @ 70% Please note:Black on white Reverse (white) on darker tones The black logo should never appear on in any ‘dark’ colour • in your gemfile: background. 5 Branding Guidelines • gem ‘mongo’ • gem ‘bson’ • gem ‘bson_ext’Wednesday, 23 January 13
  22. 22. Shutl Main Red: Shutl Accent Red: Pantone 485 C Pantone 484 C Let’s get going: C0 M100 Y99 K4 C0 M100 Y99 K4 R208 G31 B40 R208 G31 B40red on white HEX D01F28 HEX D01F28 red on lighter tones Shutl Black: Shutl Accent Grey: Pantone BLACK Pantone BLACK • install mongodb with brew install mongodb C0 M0 Y0 K0100 C0 M0 Y0 K70 @ 70% Please note:Black on white Reverse (white) on darker tones The black logo should never appear on in any ‘dark’ colour • in your gemfile: background. 5 Branding Guidelines • gem ‘mongo’ • gem ‘bson’ • gem ‘bson_ext’ • run bundle installWednesday, 23 January 13
  23. 23. MongoMapperWednesday, 23 January 13
  24. 24. MongoMapper • http://mongomapper.com/Wednesday, 23 January 13
  25. 25. MongoMapper • http://mongomapper.com/ • written by John Nunemaker (github)Wednesday, 23 January 13
  26. 26. MongoMapper • http://mongomapper.com/ • written by John Nunemaker (github) • code at https://github.com/jnunemaker/ mongomapperWednesday, 23 January 13
  27. 27. Alternatives:Wednesday, 23 January 13
  28. 28. Alternatives: • Mongoid: http://mongoid.org/en/mongoid/index.htmlWednesday, 23 January 13
  29. 29. Alternatives: • Mongoid: http://mongoid.org/en/mongoid/index.html • MongoODM: https://github.com/carlosparamio/mongo_odmWednesday, 23 January 13
  30. 30. Alternatives: • Mongoid: http://mongoid.org/en/mongoid/index.html • MongoODM: https://github.com/carlosparamio/mongo_odm • MongoModel: http://www.mongomodel.org/Wednesday, 23 January 13
  31. 31. installation:Wednesday, 23 January 13
  32. 32. installation: • in your gemfile:Wednesday, 23 January 13
  33. 33. installation: • in your gemfile: • gem ‘mongo_mapper’Wednesday, 23 January 13
  34. 34. installation: • in your gemfile: • gem ‘mongo_mapper’ • run bundle installWednesday, 23 January 13
  35. 35. db initialization:include MongoMapperMongoMapper.connection =Mongo::Connection.new(localhost, 27017)MongoMapper.database = ‘development’MongoMapper.database.authenticate(username,password)Wednesday, 23 January 13
  36. 36. First document: class User include MongoMapper::Document key :name, String, required: true key :age, Integer one :address many :notes timestamps! endWednesday, 23 January 13
  37. 37. embedded document: class Note include MongoMapper::EmbeddedDocument key :text, String endWednesday, 23 January 13
  38. 38. create a document: user = User.new(name:James Chester) user.notes.build(text:a note) user.save! User.where(:name => James Chester).firstWednesday, 23 January 13
  39. 39. What is an embedded document?Wednesday, 23 January 13
  40. 40. What is an embedded document? • a document has it’s own collection in the database (table)Wednesday, 23 January 13
  41. 41. What is an embedded document? • a document has it’s own collection in the database (table) • an embedded document can only reside inside a document or another embedded documentWednesday, 23 January 13
  42. 42. What is an embedded document? • a document has it’s own collection in the database (table) • an embedded document can only reside inside a document or another embedded document • the alternative in sql without join table would be to serializeWednesday, 23 January 13
  43. 43. What is an embedded document? • a document has it’s own collection in the database (table) • an embedded document can only reside inside a document or another embedded document • the alternative in sql without join table would be to serialize • in MongoDB it is possible to query inside embedded documents and structures and also to index inside themWednesday, 23 January 13
  44. 44. When to use embedded and when not toWednesday, 23 January 13
  45. 45. When to use embedded and when not to • only embed when the document will be shown in the context of the parent documentWednesday, 23 January 13
  46. 46. When to use embedded and when not to • only embed when the document will be shown in the context of the parent document • if you need to access to the documents on it’s own use associations (i.e. all notes)Wednesday, 23 January 13
  47. 47. When to use embedded and when not to • only embed when the document will be shown in the context of the parent document • if you need to access to the documents on it’s own use associations (i.e. all notes) • they work the same way but declare a normal document instead of an embedded oneWednesday, 23 January 13
  48. 48. { id: 50fd8a786bcb608e1c000002, name: James Chester, address: {}, notes: [ { id: 50fd8b246bcb608e1c000003, text: a note} ] }Wednesday, 23 January 13
  49. 49. types:Wednesday, 23 January 13
  50. 50. types: • mongomapper supports the ruby data types: Integer, Float, String, Array, Hash, Object, Time, NilClassWednesday, 23 January 13
  51. 51. types: • mongomapper supports the ruby data types: Integer, Float, String, Array, Hash, Object, Time, NilClass • additionally mongomapper adds support for: Binary, Boolean, Date, ObjectId and SetWednesday, 23 January 13
  52. 52. types: • mongomapper supports the ruby data types: Integer, Float, String, Array, Hash, Object, Time, NilClass • additionally mongomapper adds support for: Binary, Boolean, Date, ObjectId and Set • ability to add custom typesWednesday, 23 January 13
  53. 53. custom types: class UpcaseString def self.to_mongo(value) value.nil? ? nil : value.to_s.upcase end def self.from_mongo(value) to_mongo(value) end endWednesday, 23 January 13
  54. 54. finding a document:Wednesday, 23 January 13
  55. 55. finding a document: • find by id: User.find(‘50fd8a726bcb608e1c000001’)Wednesday, 23 January 13
  56. 56. finding a document: • find by id: User.find(‘50fd8a726bcb608e1c000001’) • find by field: User.first(:name => James)Wednesday, 23 January 13
  57. 57. finding a document: • find by id: User.find(‘50fd8a726bcb608e1c000001’) • find by field: User.first(:name => James) • query inside embedded document or structure (Hash) User.all(‘address.postcode’ => EC2A 4HJ)Wednesday, 23 January 13
  58. 58. finding a document: • find by id: User.find(‘50fd8a726bcb608e1c000001’) • find by field: User.first(:name => James) • query inside embedded document or structure (Hash) User.all(‘address.postcode’ => EC2A 4HJ) • finders are: .find, .all, .first, .last, .paginateWednesday, 23 January 13
  59. 59. dynamic querying:Wednesday, 23 January 13
  60. 60. dynamic querying: • MongoMapper uses plucky to the allow the construction of query proxy objects that only get executed when neededWednesday, 23 January 13
  61. 61. dynamic querying: • MongoMapper uses plucky to the allow the construction of query proxy objects that only get executed when needed • https://github.com/jnunemaker/pluckyWednesday, 23 January 13
  62. 62. dynamic querying: • MongoMapper uses plucky to the allow the construction of query proxy objects that only get executed when needed • https://github.com/jnunemaker/plucky • User.where(:created_at.gte => 3.days.ago).sort(:created.desc)Wednesday, 23 January 13
  63. 63. dynamic querying: • MongoMapper uses plucky to the allow the construction of query proxy objects that only get executed when needed • https://github.com/jnunemaker/plucky • User.where(:created_at.gte => 3.days.ago).sort(:created.desc) • .where, .count, .field, .sort/.order, .limit, .skip, .offsetWednesday, 23 January 13
  64. 64. operators:Wednesday, 23 January 13
  65. 65. operators: • all mongodb operators can be used directly in mongomapperWednesday, 23 January 13
  66. 66. operators: • all mongodb operators can be used directly in mongomapper • http://docs.mongodb.org/manual/reference/operators/Wednesday, 23 January 13
  67. 67. operators: • all mongodb operators can be used directly in mongomapper • http://docs.mongodb.org/manual/reference/operators/ • User.where(:age => {:$gt => 20, :$lt => 45})Wednesday, 23 January 13
  68. 68. operators: • all mongodb operators can be used directly in mongomapper • http://docs.mongodb.org/manual/reference/operators/ • User.where(:age => {:$gt => 20, :$lt => 45}) • or shorthand:Wednesday, 23 January 13
  69. 69. operators: • all mongodb operators can be used directly in mongomapper • http://docs.mongodb.org/manual/reference/operators/ • User.where(:age => {:$gt => 20, :$lt => 45}) • or shorthand: • User.where(:age.gt => 25)Wednesday, 23 January 13
  70. 70. destroy/delete:Wednesday, 23 January 13
  71. 71. destroy/delete: • destroy triggers callbacks, delete does notWednesday, 23 January 13
  72. 72. destroy/delete: • destroy triggers callbacks, delete does not • User.destroy(‘50fd8a786bcb608e1c000002’)Wednesday, 23 January 13
  73. 73. destroy/delete: • destroy triggers callbacks, delete does not • User.destroy(‘50fd8a786bcb608e1c000002’) • User.destroy_allWednesday, 23 January 13
  74. 74. destroy/delete: • destroy triggers callbacks, delete does not • User.destroy(‘50fd8a786bcb608e1c000002’) • User.destroy_all • User.destroy_all(:age.gt => 25)Wednesday, 23 January 13
  75. 75. validations: MongoMapper uses Rails ActiveModel:Validations http://api.rubyonrails.org/classes/ActiveModel/Validations.htmlWednesday, 23 January 13
  76. 76. include MongoMapper::Document key :name, String, required: true key :age, Integer validates_numericality_of :age validates :age_larger_18 def age_larger_18 errors.add( :age, "too young") if age < 18 end endWednesday, 23 January 13
  77. 77. shorthands available: :required – Boolean :unique – Boolean :numeric – Boolean :format – Regexp :in – Array :not_in – Array :length – Integer, Range, or HashWednesday, 23 January 13
  78. 78. indexes:Wednesday, 23 January 13
  79. 79. indexes: • put indexes into the initializerWednesday, 23 January 13
  80. 80. indexes: • put indexes into the initializer • index on single field: User.ensure_index(:name)Wednesday, 23 January 13
  81. 81. indexes: • put indexes into the initializer • index on single field: User.ensure_index(:name) • index multiple keys: User.ensure_index([[:name, 1], [:age, -1]])Wednesday, 23 January 13
  82. 82. indexes: • put indexes into the initializer • index on single field: User.ensure_index(:name) • index multiple keys: User.ensure_index([[:name, 1], [:age, -1]]) • the order of keys is important in compound indexesWednesday, 23 January 13
  83. 83. indexes: • put indexes into the initializer • index on single field: User.ensure_index(:name) • index multiple keys: User.ensure_index([[:name, 1], [:age, -1]]) • the order of keys is important in compound indexes • unique index: User.ensure_index [[:name, 1]], :unique => trueWednesday, 23 January 13
  84. 84. indexes: • put indexes into the initializer • index on single field: User.ensure_index(:name) • index multiple keys: User.ensure_index([[:name, 1], [:age, -1]]) • the order of keys is important in compound indexes • unique index: User.ensure_index [[:name, 1]], :unique => true • delete index: User.drop_index(:name)Wednesday, 23 January 13
  85. 85. using the decorator/presenter pattern for schemaless dbs decorator ‘decorates’ object for presentation controller passes decorated object to view retrieves object view mongo DBWednesday, 23 January 13
  86. 86. Any questions? Volker Pacher volker@shutl.co.uk shutl.co.uk @vpacher @shutlWednesday, 23 January 13

×