SlideShare a Scribd company logo
1 of 37
Download to read offline
Mongoid




            Mongoid

           Cyril Mougel


          17 Janvier 2013
Mongoid
 Mongoid c’est ?




      1    Mongoid c’est ?



      2    Mais MongoDB ?



      3    Mongoid c’est aussi ?
Mongoid
 Mongoid c’est ?



      Qu’est ce que Mongoid ?




              Un ODM Object Document Model
              ´
              Ecrit en Ruby
              API comme ActiveRecord
Mongoid
 Mongoid c’est ?



      Exemple simple




      class User
        include Mongoid :: Document
      end
Mongoid
 Mongoid c’est ?



      R´sultat
       e




      > user = User . new
      = > # < User _id : 50 f07c2444fd9947a7000001 , _type :
          nil >
Mongoid
 Mongoid c’est ?




                   D´finition des champs
                    e
Mongoid
 Mongoid c’est ?




      class User
        include Mongoid :: Document

        field : first_name
        field : last_name
      end
Mongoid
 Mongoid c’est ?




      > user = User . new (: first_name = > 123 , : last_name
            = > " Mougel " )
      = > # < User _id : 50 f07c4c44fd9947a7000003 , _type :
          nil , first_name : 123 , last_name : " Mougel " >

      > user . first_name
      = > 123

      > user . last_name
      = > " Mougel "
Mongoid
 Mongoid c’est ?




                   Gestion de la Coercion
Mongoid
 Mongoid c’est ?




      class User
        include Mongoid :: Document

        field : first_name , : type = > String
        field : last_name , : type = > String
      end
Mongoid
 Mongoid c’est ?




      > user = User . new (: first_name = > 123 , : last_name
            = > true )
      = > # < User _id : 50 f07c4c44fd9947a7000003 , _type :
          nil , first_name : "123" , last_name : " true " >

      > user . first_name
      = > " 123 "

      > user . last_name
      = > " true "
Mongoid
 Mongoid c’est ?




        Gestion d’un valeur par d´faut
                                 e
Mongoid
 Mongoid c’est ?




      class User
        include Mongoid :: Document

        field : first_name , : type = > String
        field : last_name , : type = > String
        field : location , : type = > String ,
          : default = > " Nantes "
      end
Mongoid
 Mongoid c’est ?




      > user = User . new
      = > # < User _id : 50 f07cbc44fd9947a7000004 , _type :
          nil , first_name : nil , last_name : nil ,
          location : " Nantes " >

      > user . first_name
      = > nil

      > user . location
      = > " Nantes "
Mongoid
 Mongoid c’est ?




                   Multiple Type de base
Mongoid
 Mongoid c’est ?




             BigDecimal   Date
             Boolean      DateTime
             Integer      Time
             String       Array
             Symbol       Hash
             Float
Mongoid
 Mais MongoDB ?




     1   Mongoid c’est ?



     2   Mais MongoDB ?



     3   Mongoid c’est aussi ?
Mongoid
 Mais MongoDB ?




                  Base NoSQL
                  NoSQL == Not Only SQL
Mongoid
 Mais MongoDB ?




                  Base de donn´e orient´
                              e        e
                        document
                      stockage sous format BSON

                       BSON == Binary JSON
Mongoid
 Mais MongoDB ?




                  Base de donn´e orient´
                              e        e
                        document
            Cr´ation automatique du sch´ma
              e                        e
            Pas d’obligation d’homog´n´it´ des documents
                                    e e e
Mongoid
 Mais MongoDB ?




                  Pas de jointure
Mongoid
 Mais MongoDB ?




                    Query Op´rator
                            e
            $in
            $nin
            $or
            $gt
            $lt
            etc..
Mongoid
 Mongoid c’est aussi ?




       1   Mongoid c’est ?



       2   Mais MongoDB ?



       3   Mongoid c’est aussi ?
Mongoid
 Mongoid c’est aussi ?




                         Include ActiveModel
              Gestion des erreurs
              Gestion des callbacks
Mongoid
 Mongoid c’est aussi ?




                   Gestion des associations
Mongoid
 Mongoid c’est aussi ?




              Association entre collection
              has many :orders
              belongs to :user
Mongoid
 Mongoid c’est aussi ?




       class User
         include Mongoid :: Document

         has_many : posts
       end

       class Post
         include Mongoid :: Document

         belongs_to : user
       end
Mongoid
 Mongoid c’est aussi ?




       > user = User . new
       > user . posts = [ Post . new ]
       > user . save

       > user
       = > # < User _id : 50 f07c2444fd9947a7000001 , _type :
           nil >

       > user . posts
       = > [ # < Post _id : 50 f07c2444fd9947a7000002 , _type :
             nil >]
Mongoid
 Mongoid c’est aussi ?




              Association des documents
                      embarqu´s
                              e
              embeds many :comments
              embedded in :post
Mongoid
 Mongoid c’est aussi ?




       class Post
         include Mongoid :: Document

         embeds_many : comments
       end

       class Comment
         include Mongoid :: Document

         embedded_in : post
       end
Mongoid
 Mongoid c’est aussi ?




       > user = User . new
       > user . comments = [ Comment . new ]
       > user . save

       > user
       = > # < User _id : 50 f07c2444fd9947a7000001 , _type :
           nil >

       {
           ’ _id ’: 50 f07c2444fd9947a7000001 ,
           ’ comments ’: [{
              ’ _id ’: 50 f 0 7 c 2 4 4 4 f d 9 9 4 7 a 7 0 0 0 0 0 2
           }]
       }
Mongoid
 Mongoid c’est aussi ?




                             Criteria
              Model.where           Model.asc
              Model.all in          Model.desc
              Model.any in          Model.limit
              Model.any of          Model.only
Mongoid
 Mongoid c’est aussi ?




              Les criterias sont chainable
Mongoid
 Mongoid c’est aussi ?




             Les criterias sont ´valu´s de
                                e    e
                     mani`re lazy
                           e
Mongoid
 Mongoid c’est aussi ?




                               Finder
              Model.all
              Model.first
              Model.last
              Model.exists ?
              Model.find
Mongoid
 Mongoid c’est aussi ?




                                   Moped
              MongoDB driver d´velopp´ par la communaut´ Mongoid
                              e      e                 e
              Gestion plus threadsafe par session
Mongoid
 Mongoid c’est aussi ?




                         Plus d’information ?
                                    RTFM

              http ://mongoid.org

More Related Content

Similar to Mongoid

From Zero to Mongo, Art.sy Experience w/ MongoDB
From Zero to Mongo, Art.sy Experience w/ MongoDBFrom Zero to Mongo, Art.sy Experience w/ MongoDB
From Zero to Mongo, Art.sy Experience w/ MongoDBDaniel Doubrovkine
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Railsrfischer20
 
Using Mongoid with Ruby on Rails
Using Mongoid with Ruby on RailsUsing Mongoid with Ruby on Rails
Using Mongoid with Ruby on RailsNicholas Altobelli
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEANTroy Miles
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBMongoDB
 
Content Mangement Systems and MongoDB
Content Mangement Systems and MongoDBContent Mangement Systems and MongoDB
Content Mangement Systems and MongoDBMitch Pirtle
 
Simple hack: use multiple mongodb databases in a nodejs express mongodb appli...
Simple hack: use multiple mongodb databases in a nodejs express mongodb appli...Simple hack: use multiple mongodb databases in a nodejs express mongodb appli...
Simple hack: use multiple mongodb databases in a nodejs express mongodb appli...Manoj Mohanan
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBMongoDB
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Consjohnrjenson
 
Mongo NYC PHP Development
Mongo NYC PHP Development Mongo NYC PHP Development
Mongo NYC PHP Development Fitz Agard
 
Mongo db tutorials
Mongo db tutorialsMongo db tutorials
Mongo db tutorialsAnuj Jain
 
MongoDB Days Silicon Valley: Introducing MongoDB 3.2
MongoDB Days Silicon Valley: Introducing MongoDB 3.2MongoDB Days Silicon Valley: Introducing MongoDB 3.2
MongoDB Days Silicon Valley: Introducing MongoDB 3.2MongoDB
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud OperationEdureka!
 
Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)
Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)
Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)ecommerce poland expo
 

Similar to Mongoid (20)

From Zero to Mongo, Art.sy Experience w/ MongoDB
From Zero to Mongo, Art.sy Experience w/ MongoDBFrom Zero to Mongo, Art.sy Experience w/ MongoDB
From Zero to Mongo, Art.sy Experience w/ MongoDB
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Using Mongoid with Ruby on Rails
Using Mongoid with Ruby on RailsUsing Mongoid with Ruby on Rails
Using Mongoid with Ruby on Rails
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEAN
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
 
MongoDB Part 2
MongoDB Part 2MongoDB Part 2
MongoDB Part 2
 
Content Mangement Systems and MongoDB
Content Mangement Systems and MongoDBContent Mangement Systems and MongoDB
Content Mangement Systems and MongoDB
 
Simple hack: use multiple mongodb databases in a nodejs express mongodb appli...
Simple hack: use multiple mongodb databases in a nodejs express mongodb appli...Simple hack: use multiple mongodb databases in a nodejs express mongodb appli...
Simple hack: use multiple mongodb databases in a nodejs express mongodb appli...
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
 
Mongo NYC PHP Development
Mongo NYC PHP Development Mongo NYC PHP Development
Mongo NYC PHP Development
 
Mongo db tutorials
Mongo db tutorialsMongo db tutorials
Mongo db tutorials
 
Mongo db presentaion
Mongo db presentaionMongo db presentaion
Mongo db presentaion
 
Mongodb With Mongoid
Mongodb With MongoidMongodb With Mongoid
Mongodb With Mongoid
 
MongoDB Days Silicon Valley: Introducing MongoDB 3.2
MongoDB Days Silicon Valley: Introducing MongoDB 3.2MongoDB Days Silicon Valley: Introducing MongoDB 3.2
MongoDB Days Silicon Valley: Introducing MongoDB 3.2
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud Operation
 
A Brief MongoDB Intro
A Brief MongoDB IntroA Brief MongoDB Intro
A Brief MongoDB Intro
 
Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)
Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)
Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)
 
Mongodb mongoid
Mongodb mongoidMongodb mongoid
Mongodb mongoid
 

Recently uploaded

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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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
 
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
 

Recently uploaded (20)

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
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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...
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
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
 

Mongoid

  • 1. Mongoid Mongoid Cyril Mougel 17 Janvier 2013
  • 2. Mongoid Mongoid c’est ? 1 Mongoid c’est ? 2 Mais MongoDB ? 3 Mongoid c’est aussi ?
  • 3. Mongoid Mongoid c’est ? Qu’est ce que Mongoid ? Un ODM Object Document Model ´ Ecrit en Ruby API comme ActiveRecord
  • 4. Mongoid Mongoid c’est ? Exemple simple class User include Mongoid :: Document end
  • 5. Mongoid Mongoid c’est ? R´sultat e > user = User . new = > # < User _id : 50 f07c2444fd9947a7000001 , _type : nil >
  • 6. Mongoid Mongoid c’est ? D´finition des champs e
  • 7. Mongoid Mongoid c’est ? class User include Mongoid :: Document field : first_name field : last_name end
  • 8. Mongoid Mongoid c’est ? > user = User . new (: first_name = > 123 , : last_name = > " Mougel " ) = > # < User _id : 50 f07c4c44fd9947a7000003 , _type : nil , first_name : 123 , last_name : " Mougel " > > user . first_name = > 123 > user . last_name = > " Mougel "
  • 9. Mongoid Mongoid c’est ? Gestion de la Coercion
  • 10. Mongoid Mongoid c’est ? class User include Mongoid :: Document field : first_name , : type = > String field : last_name , : type = > String end
  • 11. Mongoid Mongoid c’est ? > user = User . new (: first_name = > 123 , : last_name = > true ) = > # < User _id : 50 f07c4c44fd9947a7000003 , _type : nil , first_name : "123" , last_name : " true " > > user . first_name = > " 123 " > user . last_name = > " true "
  • 12. Mongoid Mongoid c’est ? Gestion d’un valeur par d´faut e
  • 13. Mongoid Mongoid c’est ? class User include Mongoid :: Document field : first_name , : type = > String field : last_name , : type = > String field : location , : type = > String , : default = > " Nantes " end
  • 14. Mongoid Mongoid c’est ? > user = User . new = > # < User _id : 50 f07cbc44fd9947a7000004 , _type : nil , first_name : nil , last_name : nil , location : " Nantes " > > user . first_name = > nil > user . location = > " Nantes "
  • 15. Mongoid Mongoid c’est ? Multiple Type de base
  • 16. Mongoid Mongoid c’est ? BigDecimal Date Boolean DateTime Integer Time String Array Symbol Hash Float
  • 17. Mongoid Mais MongoDB ? 1 Mongoid c’est ? 2 Mais MongoDB ? 3 Mongoid c’est aussi ?
  • 18. Mongoid Mais MongoDB ? Base NoSQL NoSQL == Not Only SQL
  • 19. Mongoid Mais MongoDB ? Base de donn´e orient´ e e document stockage sous format BSON BSON == Binary JSON
  • 20. Mongoid Mais MongoDB ? Base de donn´e orient´ e e document Cr´ation automatique du sch´ma e e Pas d’obligation d’homog´n´it´ des documents e e e
  • 21. Mongoid Mais MongoDB ? Pas de jointure
  • 22. Mongoid Mais MongoDB ? Query Op´rator e $in $nin $or $gt $lt etc..
  • 23. Mongoid Mongoid c’est aussi ? 1 Mongoid c’est ? 2 Mais MongoDB ? 3 Mongoid c’est aussi ?
  • 24. Mongoid Mongoid c’est aussi ? Include ActiveModel Gestion des erreurs Gestion des callbacks
  • 25. Mongoid Mongoid c’est aussi ? Gestion des associations
  • 26. Mongoid Mongoid c’est aussi ? Association entre collection has many :orders belongs to :user
  • 27. Mongoid Mongoid c’est aussi ? class User include Mongoid :: Document has_many : posts end class Post include Mongoid :: Document belongs_to : user end
  • 28. Mongoid Mongoid c’est aussi ? > user = User . new > user . posts = [ Post . new ] > user . save > user = > # < User _id : 50 f07c2444fd9947a7000001 , _type : nil > > user . posts = > [ # < Post _id : 50 f07c2444fd9947a7000002 , _type : nil >]
  • 29. Mongoid Mongoid c’est aussi ? Association des documents embarqu´s e embeds many :comments embedded in :post
  • 30. Mongoid Mongoid c’est aussi ? class Post include Mongoid :: Document embeds_many : comments end class Comment include Mongoid :: Document embedded_in : post end
  • 31. Mongoid Mongoid c’est aussi ? > user = User . new > user . comments = [ Comment . new ] > user . save > user = > # < User _id : 50 f07c2444fd9947a7000001 , _type : nil > { ’ _id ’: 50 f07c2444fd9947a7000001 , ’ comments ’: [{ ’ _id ’: 50 f 0 7 c 2 4 4 4 f d 9 9 4 7 a 7 0 0 0 0 0 2 }] }
  • 32. Mongoid Mongoid c’est aussi ? Criteria Model.where Model.asc Model.all in Model.desc Model.any in Model.limit Model.any of Model.only
  • 33. Mongoid Mongoid c’est aussi ? Les criterias sont chainable
  • 34. Mongoid Mongoid c’est aussi ? Les criterias sont ´valu´s de e e mani`re lazy e
  • 35. Mongoid Mongoid c’est aussi ? Finder Model.all Model.first Model.last Model.exists ? Model.find
  • 36. Mongoid Mongoid c’est aussi ? Moped MongoDB driver d´velopp´ par la communaut´ Mongoid e e e Gestion plus threadsafe par session
  • 37. Mongoid Mongoid c’est aussi ? Plus d’information ? RTFM http ://mongoid.org