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

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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 Processorsdebabhi2
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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 Scriptwesley chun
 

Recently uploaded (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 

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