SlideShare a Scribd company logo
1 of 86
Download to read offline
MongoDB and Ruby



                       domain modeling with MongoMapper




Wednesday, 23 January 13
Volker Pacher
                           senior developer @shutl
                                    @vpacher
                           http://github.com/vpacher


Wednesday, 23 January 13
Wednesday, 23 January 13
Wednesday, 23 January 13
• SaaS platform




Wednesday, 23 January 13
• SaaS platform
      • we provide an API for carriers and merchants




Wednesday, 23 January 13
• SaaS platform
      • we provide an API for carriers and merchants
      • customers can chose between a delivery either:




Wednesday, 23 January 13
• SaaS platform
      • we provide an API for carriers and merchants
      • customers can chose between a delivery either:
                  within 90 minutes of purchase




Wednesday, 23 January 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




Wednesday, 23 January 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)




Wednesday, 23 January 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



Wednesday, 23 January 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 ...


Wednesday, 23 January 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 api

Wednesday, 23 January 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 api
      •built with sinatra, jruby, neo4j and mongodb
Wednesday, 23 January 13
Wednesday, 23 January 13
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 B40
red 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 Guidelines




Wednesday, 23 January 13
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 B40
red 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 Guidelines




Wednesday, 23 January 13
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 B40
red 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




Wednesday, 23 January 13
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 B40
red 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
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 B40
red 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
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 B40
red 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
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 B40
red 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 install



Wednesday, 23 January 13
MongoMapper




Wednesday, 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://github.com/jnunemaker/
         mongomapper




Wednesday, 23 January 13
Alternatives:




Wednesday, 23 January 13
Alternatives:




         • Mongoid: http://mongoid.org/en/mongoid/index.html




Wednesday, 23 January 13
Alternatives:




         • Mongoid: http://mongoid.org/en/mongoid/index.html
         • MongoODM: https://github.com/carlosparamio/mongo_odm




Wednesday, 23 January 13
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
installation:




Wednesday, 23 January 13
installation:




                           • in your gemfile:




Wednesday, 23 January 13
installation:




                           • in your gemfile:
                           • gem ‘mongo_mapper’




Wednesday, 23 January 13
installation:




                           • in your gemfile:
                           • gem ‘mongo_mapper’
                           • run bundle install




Wednesday, 23 January 13
db initialization:


include MongoMapper

MongoMapper.connection =
Mongo::Connection.new('localhost', 27017)
MongoMapper.database = ‘development’

MongoMapper.database.authenticate('username','password')




Wednesday, 23 January 13
First document:

                class User
                  include MongoMapper::Document

                       key :name, String, required: true
                       key :age, Integer

                       one :address
                       many :notes

                  timestamps!
                end



Wednesday, 23 January 13
embedded document:

        class Note
          include MongoMapper::EmbeddedDocument

          key :text, String
        end




Wednesday, 23 January 13
create a document:
    user = User.new(name:'James Chester')
    user.notes.build(text:'a note')

    user.save!

    User.where(:name => 'James Chester').first




Wednesday, 23 January 13
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 document can only reside inside a document
          or another embedded document




Wednesday, 23 January 13
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




Wednesday, 23 January 13
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 them




Wednesday, 23 January 13
When to use embedded and when not to




Wednesday, 23 January 13
When to use embedded and when not to


          • only embed when the document will be shown in the
          context of the parent document




Wednesday, 23 January 13
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
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 one




Wednesday, 23 January 13
{
       id:     '50fd8a786bcb608e1c000002',
      name: 'James Chester',
      address: {},
      notes:
         [
           { id: '50fd8b246bcb608e1c000003', text: 'a note'}
         ]
  }


Wednesday, 23 January 13
types:




Wednesday, 23 January 13
types:


  • mongomapper supports the ruby data types:
       Integer, Float, String, Array, Hash, Object, Time, NilClass




Wednesday, 23 January 13
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




Wednesday, 23 January 13
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 types




Wednesday, 23 January 13
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
    end




Wednesday, 23 January 13
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, 23 January 13
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
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, .paginate




Wednesday, 23 January 13
dynamic querying:




Wednesday, 23 January 13
dynamic querying:

  • MongoMapper uses plucky to the allow the construction of query
  proxy objects that only get executed when needed




Wednesday, 23 January 13
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




Wednesday, 23 January 13
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
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, .offset




Wednesday, 23 January 13
operators:




Wednesday, 23 January 13
operators:


   • all mongodb operators can be used directly in mongomapper




Wednesday, 23 January 13
operators:


   • all mongodb operators can be used directly in mongomapper
   • http://docs.mongodb.org/manual/reference/operators/




Wednesday, 23 January 13
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
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
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
destroy/delete:




Wednesday, 23 January 13
destroy/delete:



                  • destroy triggers callbacks, delete does not




Wednesday, 23 January 13
destroy/delete:



                  • destroy triggers callbacks, delete does not
                  • User.destroy(‘50fd8a786bcb608e1c000002’)




Wednesday, 23 January 13
destroy/delete:



                  • destroy triggers callbacks, delete does not
                  • User.destroy(‘50fd8a786bcb608e1c000002’)
                  • User.destroy_all




Wednesday, 23 January 13
destroy/delete:



                  • destroy triggers callbacks, delete does not
                  • User.destroy(‘50fd8a786bcb608e1c000002’)
                  • User.destroy_all
                  • User.destroy_all(:age.gt => 25)




Wednesday, 23 January 13
validations:




                    MongoMapper uses Rails ActiveModel:Validations

    http://api.rubyonrails.org/classes/ActiveModel/Validations.html




Wednesday, 23 January 13
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
   end




Wednesday, 23 January 13
shorthands available:


                           :required – Boolean
                           :unique – Boolean
                           :numeric – Boolean
                           :format – Regexp
                           :in      – Array
                           :not_in – Array
                           :length – Integer, Range, or Hash




Wednesday, 23 January 13
indexes:




Wednesday, 23 January 13
indexes: • put indexes into the initializer




Wednesday, 23 January 13
indexes: • put indexes into the initializer
            • index on single field:
                           User.ensure_index(:name)




Wednesday, 23 January 13
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
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




Wednesday, 23 January 13
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




Wednesday, 23 January 13
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
using the decorator/presenter pattern for schemaless dbs


                                                  decorator




                                                          ‘decorates’ object for presentation




                                                  controller

                                                                          passes decorated object to view

                               retrieves object
                                                                                                view



                           mongo
                            DB

Wednesday, 23 January 13
Any questions?

  Volker Pacher


  volker@shutl.co.uk                        shutl.co.uk
  @vpacher                                     @shutl
Wednesday, 23 January 13

More Related Content

Recently uploaded

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Shutl mongob usergroup talk jan 2013

  • 1. MongoDB and Ruby domain modeling with MongoMapper Wednesday, 23 January 13
  • 2. Volker Pacher senior developer @shutl @vpacher http://github.com/vpacher Wednesday, 23 January 13
  • 6. • SaaS platform • we provide an API for carriers and merchants Wednesday, 23 January 13
  • 7. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either: Wednesday, 23 January 13
  • 8. • SaaS platform • we provide an API for carriers and merchants • customers can chose between a delivery either: within 90 minutes of purchase Wednesday, 23 January 13
  • 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 choice Wednesday, 23 January 13
  • 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. • 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 Wednesday, 23 January 13
  • 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. • 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 Wednesday, 23 January 13
  • 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 mongodb Wednesday, 23 January 13
  • 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 B40 red 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 Guidelines Wednesday, 23 January 13
  • 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 B40 red 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 Guidelines Wednesday, 23 January 13
  • 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 B40 red 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 Wednesday, 23 January 13
  • 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 B40 red 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. 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 B40 red 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. 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 B40 red 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. 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 B40 red 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 install Wednesday, 23 January 13
  • 24. MongoMapper • http://mongomapper.com/ Wednesday, 23 January 13
  • 25. MongoMapper • http://mongomapper.com/ • written by John Nunemaker (github) Wednesday, 23 January 13
  • 26. MongoMapper • http://mongomapper.com/ • written by John Nunemaker (github) • code at https://github.com/jnunemaker/ mongomapper Wednesday, 23 January 13
  • 28. Alternatives: • Mongoid: http://mongoid.org/en/mongoid/index.html Wednesday, 23 January 13
  • 29. Alternatives: • Mongoid: http://mongoid.org/en/mongoid/index.html • MongoODM: https://github.com/carlosparamio/mongo_odm Wednesday, 23 January 13
  • 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
  • 32. installation: • in your gemfile: Wednesday, 23 January 13
  • 33. installation: • in your gemfile: • gem ‘mongo_mapper’ Wednesday, 23 January 13
  • 34. installation: • in your gemfile: • gem ‘mongo_mapper’ • run bundle install Wednesday, 23 January 13
  • 35. db initialization: include MongoMapper MongoMapper.connection = Mongo::Connection.new('localhost', 27017) MongoMapper.database = ‘development’ MongoMapper.database.authenticate('username','password') Wednesday, 23 January 13
  • 36. First document: class User include MongoMapper::Document key :name, String, required: true key :age, Integer one :address many :notes timestamps! end Wednesday, 23 January 13
  • 37. embedded document: class Note include MongoMapper::EmbeddedDocument key :text, String end Wednesday, 23 January 13
  • 38. create a document: user = User.new(name:'James Chester') user.notes.build(text:'a note') user.save! User.where(:name => 'James Chester').first Wednesday, 23 January 13
  • 39. What is an embedded document? Wednesday, 23 January 13
  • 40. What is an embedded document? • a document has it’s own collection in the database (table) Wednesday, 23 January 13
  • 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 document Wednesday, 23 January 13
  • 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 serialize Wednesday, 23 January 13
  • 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 them Wednesday, 23 January 13
  • 44. When to use embedded and when not to Wednesday, 23 January 13
  • 45. When to use embedded and when not to • only embed when the document will be shown in the context of the parent document Wednesday, 23 January 13
  • 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. 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 one Wednesday, 23 January 13
  • 48. { id: '50fd8a786bcb608e1c000002', name: 'James Chester', address: {}, notes: [ { id: '50fd8b246bcb608e1c000003', text: 'a note'} ] } Wednesday, 23 January 13
  • 50. types: • mongomapper supports the ruby data types: Integer, Float, String, Array, Hash, Object, Time, NilClass Wednesday, 23 January 13
  • 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 Set Wednesday, 23 January 13
  • 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 types Wednesday, 23 January 13
  • 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 end Wednesday, 23 January 13
  • 55. finding a document: • find by id: User.find(‘50fd8a726bcb608e1c000001’) Wednesday, 23 January 13
  • 56. finding a document: • find by id: User.find(‘50fd8a726bcb608e1c000001’) • find by field: User.first(:name => 'James') Wednesday, 23 January 13
  • 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. 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, .paginate Wednesday, 23 January 13
  • 60. dynamic querying: • MongoMapper uses plucky to the allow the construction of query proxy objects that only get executed when needed Wednesday, 23 January 13
  • 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/plucky Wednesday, 23 January 13
  • 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. 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, .offset Wednesday, 23 January 13
  • 65. operators: • all mongodb operators can be used directly in mongomapper Wednesday, 23 January 13
  • 66. operators: • all mongodb operators can be used directly in mongomapper • http://docs.mongodb.org/manual/reference/operators/ Wednesday, 23 January 13
  • 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. 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. 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
  • 71. destroy/delete: • destroy triggers callbacks, delete does not Wednesday, 23 January 13
  • 72. destroy/delete: • destroy triggers callbacks, delete does not • User.destroy(‘50fd8a786bcb608e1c000002’) Wednesday, 23 January 13
  • 73. destroy/delete: • destroy triggers callbacks, delete does not • User.destroy(‘50fd8a786bcb608e1c000002’) • User.destroy_all Wednesday, 23 January 13
  • 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. validations: MongoMapper uses Rails ActiveModel:Validations http://api.rubyonrails.org/classes/ActiveModel/Validations.html Wednesday, 23 January 13
  • 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 end Wednesday, 23 January 13
  • 77. shorthands available: :required – Boolean :unique – Boolean :numeric – Boolean :format – Regexp :in – Array :not_in – Array :length – Integer, Range, or Hash Wednesday, 23 January 13
  • 79. indexes: • put indexes into the initializer Wednesday, 23 January 13
  • 80. indexes: • put indexes into the initializer • index on single field: User.ensure_index(:name) Wednesday, 23 January 13
  • 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. 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 Wednesday, 23 January 13
  • 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 => true Wednesday, 23 January 13
  • 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. using the decorator/presenter pattern for schemaless dbs decorator ‘decorates’ object for presentation controller passes decorated object to view retrieves object view mongo DB Wednesday, 23 January 13
  • 86. Any questions? Volker Pacher volker@shutl.co.uk shutl.co.uk @vpacher @shutl Wednesday, 23 January 13