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

MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
rfischer20
 
Mongo NYC PHP Development
Mongo NYC PHP Development Mongo NYC PHP Development
Mongo NYC PHP Development
Fitz Agard
 
MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud Operation
Edureka!
 
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
 
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
 
MongoDB
MongoDBMongoDB
MongoDB
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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