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

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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Recently uploaded (20)

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
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

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