SlideShare uma empresa Scribd logo
1 de 60
Baixar para ler offline
Tuesday, February 8, 2011
Big and Fat
                            Using MongoDB with deep and diverse datasets:
                                           A case study



Tuesday, February 8, 2011
About me
                    •       My name is Jeremy McAnally

                    •       “Software architect” at Intridea

                    •       Write a lot of books, OSS, etc.

                            •   http://github.com/jm

                            •   http://twitter.com/jm

                            •   http://authoringebooks.com

                            •   http://wickhamhousebrand.com

Tuesday, February 8, 2011
New book!




Tuesday, February 8, 2011
New book!
                                     s
                                    y y
                                   a a
                                 d d
                                2 to
                              -
                              ro m
                            f
Tuesday, February 8, 2011
Preface
                            The Application   ™




Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
Disclaimer
               We moved to (mostly) sql.



Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
YAK SHAVE
YAK SHAVE
     SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
     SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK SHAVE
YAK
YAK
Tuesday, February 8, 2011
Lesson 1
                   Abstraction is a double-
                       edged sword.


Tuesday, February 8, 2011
Abstract away!
           Talking to all data (no matter
           the source) the same way will
                  keep you sane.




Tuesday, February 8, 2011
users  =  MySQL::Query.execute("SELECT  *  FROM  users;")

                 users.each  do  |u|
                     posts  =  db.collection('posts').find(:user_id  =>  u['id'])
                     #  [...]
                     comments  =  db.collection('comments').find("$where"  =>  "sum
                 (this.admin_count,  this.moderator_count)  ==  5")
                 end




Tuesday, February 8, 2011
users  =  User.all

                      users.each  do  |u|
                          posts  =  Post.find(:user_id  =>  u.id)
                          #  [...]
                          comments  =  Comment.where("sum(this.admin_count,  
                                                                              this.moderator_count)  ==  5")
                      end




Tuesday, February 8, 2011
users  =  User.all

                      users.each  do  |u|
                          posts  =  Post.find(:user_id  =>  u.id)
                          #  [...]
                          comments  =  Comment.with_five_things
                      end




Tuesday, February 8, 2011
...but wait!
        MongoDB has a lot of features
        that will perform better and be
          less (and often better) code.




Tuesday, February 8, 2011
pharmacists  =  {}

                            Patient.all.each  do  |patient|
                                patient.prescriptions.each  do  |prescription|
                                    pharmacists[presciption.name]  ||=  0
                                    pharmacists[presciption.name]  +=  1
                                end
                            end




Tuesday, February 8, 2011
AS
                                 W P
                            pharmacists  =  {}




                               O A
                            Patient.all.each  do  |patient|



                              L
                                patient.prescriptions.each  do  |prescription|



                             S R
                                    pharmacists[presciption.name]  ||=  0
                                    pharmacists[presciption.name]  +=  1
                                end



                                C
                            end




Tuesday, February 8, 2011
map  =  "function(){
                                    this.prescriptions.forEach(
                                        function(p)  {  
                                            emit(p.name,  {  count  :  1  });
                                    })}"  
                                
                            reduce  =  "function(k,  v)  {
                                var  number  =  0;
                                for  v.forEach(function()  {
                                    number  +=  v[i].count;
                                });
                                return  {  count  :  number  };  
                            }"  
                                
                            pharms  =  @patients.map_reduce(map,  reduce)




Tuesday, February 8, 2011
map  =  "function(){
                                    this.prescriptions.forEach(
                                        function(p)  {  
                                            emit(p.name,  {  count  :  1  });
                                    })}"  
                                
                            reduce  =  "function(k,  v)  {
                                var  number  =  0;
                                for  v.forEach(function()  {
                                    number  +=  v[i].count;
                                });
                                return  {  count  :  number  };  
                            }"  
                                
                            pharms  =  @patients.map_reduce(map,  reduce)




Tuesday, February 8, 2011
Lesson 2
                      Schema design matters.



Tuesday, February 8, 2011
DAT      Lesson 2
                       A design matters.
                  Schema
                  MOD
                      EL



Tuesday, February 8, 2011
Embedding
                      works.
          Embedding documents is a
        smart decision in a lot of cases.




Tuesday, February 8, 2011
SELECT  *  FROM  patients  WHERE  id=212;
                      SELECT  *  FROM  prescriptions  WHERE  patient_id=212;
                      SELECT  *  FROM  appointments  WHERE  patient_id=212;
                      SELECT  *  FROM  contacts  WHERE  patient_id=212;
                      SELECT  *  FROM  claims  WHERE  patient_id=212;
                      .
                      .
                      .




Tuesday, February 8, 2011
{
                            "_id"  :  ObjectId("4d51959614971661303ea716"),
                            "title"  :  "Blogs  rawk.",
                            "body"  :  "Fo  realz",
                            "comments"  :  [
                               {
                                  "user_name"  :  "Jeremy",
                                  "user_id"  :  1234,
                                  "body"  :  "Yup."
                               }
                            ]
                      }




Tuesday, February 8, 2011
...but watch it.
            You can also hit a ton of
         performance and design issues.




Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
OUR GIANT DOCUMENT
                 Mongo’s Pre-Allocated Space




Tuesday, February 8, 2011
Search,
                            listing, etc.


                                            “Reference”
                                             Pharmacy



                              Patient
                            Pharmacy


Tuesday, February 8, 2011
Lesson 3
                            Don’t go nuts.



Tuesday, February 8, 2011
OH MAN MONGO
                                             JUST GOT REAL UP
                                                  IN HERE



                Schemaless is
                    fun!
         Having schemaless data has its
          own battery of advantages.

                                          nosql




Tuesday, February 8, 2011
Schemaless Joy
                    •       Transforming data models is a delight




Tuesday, February 8, 2011
Tuesday, February 8, 2011
Schemaless Joy
                    •       Transforming data models is a delight

                    •       Formless data isn’t awkward




Tuesday, February 8, 2011
{
                         "_id"  :  ObjectId("4d50c6c32472473e54122d29"),
                         "name"  :  "Subject  A",
                         "2007"  :  199,
                         "2008"  :  2002,
                         "2010"  :  387
                      },
                      {
                         "_id"  :  ObjectId("4d50c6d92472473e54122d2a"),
                         "name"  :  "Subject  B",
                         "2005"  :  8,
                         "2008"  :  99,
                         "2012"  :  466
                      },
                      {
                         "_id"  :  ObjectId("4d50c6f52472473e54122d2b"),
                         "name"  :  "Subject  C",
                         "2005"  :  100,
                         "2009"  :  120,
                         "2010"  :  1201,
                         "2012"  :  3469
                      }

Tuesday, February 8, 2011
>  db.subjects.find({2008:  {$ne:  null}})      
  {  "_id"  :  ObjectId("4d50c6c32472473e54122d29"),  "name"  :  "Subject  A"
  {  "_id"  :  ObjectId("4d50c6d92472473e54122d2a"),  "name"  :  "Subject  B"




Tuesday, February 8, 2011
Schemaless Joy
                    •       Transforming data models is a delight

                    •       Formless data isn’t awkward

                    •       Arbitrary embedding is awesome




Tuesday, February 8, 2011
Tuesday, February 8, 2011
Schemaless Joy
                    •       Transforming data models is a delight

                    •       Formless data isn’t awkward

                    •       Arbitrary embedding is awesome

                    •       Building to work with schemaless data can lead
                            to some really powerful app concepts




Tuesday, February 8, 2011
...but be wary.
                   Going nuts will create
                    headaches for you.




Tuesday, February 8, 2011
Schemaless Pain




Tuesday, February 8, 2011
Schemaless Pain

                    •       Weird app behavior




Tuesday, February 8, 2011
Schemaless Pain

                    •       Weird app behavior

                    •       Huge, long-running data transformations




Tuesday, February 8, 2011
Schemaless Pain

                    •       Weird app behavior

                    •       Huge, long-running data transformations

                    •       Annoying data transforms for development env’s




Tuesday, February 8, 2011
Schemaless Pain

                    •       Weird app behavior

                    •       Huge, long-running data transformations

                    •       Annoying data transforms for development env’s

                    •       Difficult to version data models




Tuesday, February 8, 2011
Lesson 4
                            Dig deep.



Tuesday, February 8, 2011
>  db.runCommand({"serverStatus"  :  1})
                            {
                               "version"  :  "1.4.3",
                               "uptime"  :  96,
                               "localTime"  :  "Thu  Nov  18  2010  01:49:38  
                            GMT-­‐0500  (EST)",
                               "globalLock"  :  {
                                  "totalTime"  :  96005290,
                                  "lockTime"  :  174040,
                                  "ratio"  :  0.0018128167729090762
                               },
                               "mem"  :  {
                                  "bits"  :  64,
                                  "resident"  :  2,
                                  "virtual"  :  2396,
                                  "supported"  :  true,
                                  "mapped"  :  0
                               },
                               "connections"  :  {
                                  "current"  :  1,
                                  "available"  :  19999
                               },
Tuesday, February 8, 2011      "extra_info"  :  {
"opcounters"  :  {
                                "insert"  :  0,
                                "query"  :  1,
                                "update"  :  0,
                                "delete"  :  0,
                                "getmore"  :  0,
                                "command"  :  3
                            }




Tuesday, February 8, 2011
"connections"  :  {
                                "current"  :  1,
                                "available"  :  19999
                            }




Tuesday, February 8, 2011
Jeremy-­‐McAnallys-­‐MacBook-­‐Pro:~  jeremymcanally$  mongostat
  connected  to:  127.0.0.1
  insert/s  query/s  update/s  delete/s  getmore/s  command/s  mapped    vsize        res  %  locked  %  idx  miss    conn  
                0              0                0                0                  0                  1            0      2396            3                0                    0          1  
                0              0                0                0                  0                  1            0      2396            3                0                    0          1  
                0              0                0                0                  0                  1            0      2396            3                0                    0          1  
                0              0                0                0                  0                  1            0      2396            3                0                    0          1  
                0              0                0                0                  0                  1            0      2396            3                0                    0          1  
                0              0                0                0                  0                  1            0      2396            3                0                    0          1  
                0              0                0                0                  0                  1            0      2396            3                0                    0          1  
                0              0                0                0                  0                  1            0      2396            3                0                    0          1  




Tuesday, February 8, 2011
Tuesday, February 8, 2011
db._adminCommand({  diagLogging  :  1  })




Tuesday, February 8, 2011
db.currentOp()
                {  inprog:  [  {  "opid"  :  35  ,  "op"  :  "query"  ,  "ns"  :  
                "fundb.parties"  ,
                                            "query"  :  "{  score  :  1.0  }"  ,  "inLock"  :  1  }
                                    ]
                }




Tuesday, February 8, 2011
>  db.oplog.$main.find()
     {  "ts"  :  {  "t"  :  1290063566000,  "i"  :  1  },  "op"  :  "i",  "ns"  :  "ming
     {  "ts"  :  {  "t"  :  1290063569000,  "i"  :  1  },  "op"  :  "n",  "ns"  :  "",  "
     {  "ts"  :  {  "t"  :  1290063579000,  "i"  :  1  },  "op"  :  "n",  "ns"  :  "",  "
     {  "ts"  :  {  "t"  :  1290063581000,  "i"  :  1  },  "op"  :  "i",  "ns"  :  "ming
     {  "ts"  :  {  "t"  :  1290063581000,  "i"  :  2  },  "op"  :  "i",  "ns"  :  "ming




Tuesday, February 8, 2011
{  "ts"  :  
                         {  "t"  :  1290063566000,  
                             "i"  :  1  
                         },  
                         "op"  :  "i",  
                         "ns"  :  "ming.foo",  
                         "o"  :  {  
                               "_id"  :  ObjectId("4ce4ceceabb1b65158000001"),  
                               "field"  :  2  
                         }  
                     }




Tuesday, February 8, 2011
That’s all I got.
                            Questions?



Tuesday, February 8, 2011

Mais conteúdo relacionado

Destaque (11)

Area cultura funzione strumentale
Area cultura funzione strumentaleArea cultura funzione strumentale
Area cultura funzione strumentale
 
Ppmate1]
Ppmate1]Ppmate1]
Ppmate1]
 
Educ sexual (1)
Educ sexual (1)Educ sexual (1)
Educ sexual (1)
 
Fotografia
FotografiaFotografia
Fotografia
 
Hooligan interview
Hooligan interviewHooligan interview
Hooligan interview
 
Leadership & Change Magazine
Leadership & Change MagazineLeadership & Change Magazine
Leadership & Change Magazine
 
Ingles
InglesIngles
Ingles
 
Locandina Giornata della Memoria 2011
Locandina  Giornata della Memoria 2011Locandina  Giornata della Memoria 2011
Locandina Giornata della Memoria 2011
 
Tuntunan Berorganisasi
Tuntunan BerorganisasiTuntunan Berorganisasi
Tuntunan Berorganisasi
 
The Townsend Hotel
The Townsend HotelThe Townsend Hotel
The Townsend Hotel
 
Vitanuova
VitanuovaVitanuova
Vitanuova
 

Semelhante a Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)

RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
Out Cast
 
Doctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 ParisDoctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 Paris
pablodip
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
smueller_sandsmedia
 
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
jbellis
 
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
OpenBlend society
 

Semelhante a Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version) (16)

When?, Why? and What? of MongoDB
When?, Why? and What? of MongoDBWhen?, Why? and What? of MongoDB
When?, Why? and What? of MongoDB
 
Sequel @ madrid-rb
Sequel @  madrid-rbSequel @  madrid-rb
Sequel @ madrid-rb
 
set.pptx
set.pptxset.pptx
set.pptx
 
Developing a Language
Developing a LanguageDeveloping a Language
Developing a Language
 
Developing a Language
Developing a LanguageDeveloping a Language
Developing a Language
 
Python - Data Collection
Python - Data CollectionPython - Data Collection
Python - Data Collection
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
 
Doctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 ParisDoctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 Paris
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 
pyton Notes6
 pyton Notes6 pyton Notes6
pyton Notes6
 
Building Non-shit APIs with JavaScript
Building Non-shit APIs with JavaScriptBuilding Non-shit APIs with JavaScript
Building Non-shit APIs with JavaScript
 
잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기
 
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
 
R workshop
R workshopR workshop
R workshop
 
JavaSE 7
JavaSE 7JavaSE 7
JavaSE 7
 
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 

Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)

  • 2. Big and Fat Using MongoDB with deep and diverse datasets: A case study Tuesday, February 8, 2011
  • 3. About me • My name is Jeremy McAnally • “Software architect” at Intridea • Write a lot of books, OSS, etc. • http://github.com/jm • http://twitter.com/jm • http://authoringebooks.com • http://wickhamhousebrand.com Tuesday, February 8, 2011
  • 5. New book! s y y a a d d 2 to - ro m f Tuesday, February 8, 2011
  • 6. Preface The Application ™ Tuesday, February 8, 2011
  • 9. Disclaimer We moved to (mostly) sql. Tuesday, February 8, 2011
  • 13. YAK SHAVE YAK SHAVE SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK SHAVE YAK YAK Tuesday, February 8, 2011
  • 14. Lesson 1 Abstraction is a double- edged sword. Tuesday, February 8, 2011
  • 15. Abstract away! Talking to all data (no matter the source) the same way will keep you sane. Tuesday, February 8, 2011
  • 16. users  =  MySQL::Query.execute("SELECT  *  FROM  users;") users.each  do  |u|    posts  =  db.collection('posts').find(:user_id  =>  u['id'])    #  [...]    comments  =  db.collection('comments').find("$where"  =>  "sum (this.admin_count,  this.moderator_count)  ==  5") end Tuesday, February 8, 2011
  • 17. users  =  User.all users.each  do  |u|    posts  =  Post.find(:user_id  =>  u.id)    #  [...]    comments  =  Comment.where("sum(this.admin_count,                                                          this.moderator_count)  ==  5") end Tuesday, February 8, 2011
  • 18. users  =  User.all users.each  do  |u|    posts  =  Post.find(:user_id  =>  u.id)    #  [...]    comments  =  Comment.with_five_things end Tuesday, February 8, 2011
  • 19. ...but wait! MongoDB has a lot of features that will perform better and be less (and often better) code. Tuesday, February 8, 2011
  • 20. pharmacists  =  {} Patient.all.each  do  |patient|    patient.prescriptions.each  do  |prescription|        pharmacists[presciption.name]  ||=  0        pharmacists[presciption.name]  +=  1    end end Tuesday, February 8, 2011
  • 21. AS W P pharmacists  =  {} O A Patient.all.each  do  |patient| L    patient.prescriptions.each  do  |prescription| S R        pharmacists[presciption.name]  ||=  0        pharmacists[presciption.name]  +=  1    end C end Tuesday, February 8, 2011
  • 22. map  =  "function(){        this.prescriptions.forEach(            function(p)  {                  emit(p.name,  {  count  :  1  });        })}"       reduce  =  "function(k,  v)  {    var  number  =  0;    for  v.forEach(function()  {        number  +=  v[i].count;    });    return  {  count  :  number  };   }"       pharms  =  @patients.map_reduce(map,  reduce) Tuesday, February 8, 2011
  • 23. map  =  "function(){        this.prescriptions.forEach(            function(p)  {                  emit(p.name,  {  count  :  1  });        })}"       reduce  =  "function(k,  v)  {    var  number  =  0;    for  v.forEach(function()  {        number  +=  v[i].count;    });    return  {  count  :  number  };   }"       pharms  =  @patients.map_reduce(map,  reduce) Tuesday, February 8, 2011
  • 24. Lesson 2 Schema design matters. Tuesday, February 8, 2011
  • 25. DAT Lesson 2 A design matters. Schema MOD EL Tuesday, February 8, 2011
  • 26. Embedding works. Embedding documents is a smart decision in a lot of cases. Tuesday, February 8, 2011
  • 27. SELECT  *  FROM  patients  WHERE  id=212; SELECT  *  FROM  prescriptions  WHERE  patient_id=212; SELECT  *  FROM  appointments  WHERE  patient_id=212; SELECT  *  FROM  contacts  WHERE  patient_id=212; SELECT  *  FROM  claims  WHERE  patient_id=212; . . . Tuesday, February 8, 2011
  • 28. {   "_id"  :  ObjectId("4d51959614971661303ea716"),   "title"  :  "Blogs  rawk.",   "body"  :  "Fo  realz",   "comments"  :  [     {       "user_name"  :  "Jeremy",       "user_id"  :  1234,       "body"  :  "Yup."     }   ] } Tuesday, February 8, 2011
  • 29. ...but watch it. You can also hit a ton of performance and design issues. Tuesday, February 8, 2011
  • 32. OUR GIANT DOCUMENT Mongo’s Pre-Allocated Space Tuesday, February 8, 2011
  • 33. Search, listing, etc. “Reference” Pharmacy Patient Pharmacy Tuesday, February 8, 2011
  • 34. Lesson 3 Don’t go nuts. Tuesday, February 8, 2011
  • 35. OH MAN MONGO JUST GOT REAL UP IN HERE Schemaless is fun! Having schemaless data has its own battery of advantages. nosql Tuesday, February 8, 2011
  • 36. Schemaless Joy • Transforming data models is a delight Tuesday, February 8, 2011
  • 38. Schemaless Joy • Transforming data models is a delight • Formless data isn’t awkward Tuesday, February 8, 2011
  • 39. {   "_id"  :  ObjectId("4d50c6c32472473e54122d29"),   "name"  :  "Subject  A",   "2007"  :  199,   "2008"  :  2002,   "2010"  :  387 }, {   "_id"  :  ObjectId("4d50c6d92472473e54122d2a"),   "name"  :  "Subject  B",   "2005"  :  8,   "2008"  :  99,   "2012"  :  466 }, {   "_id"  :  ObjectId("4d50c6f52472473e54122d2b"),   "name"  :  "Subject  C",   "2005"  :  100,   "2009"  :  120,   "2010"  :  1201,   "2012"  :  3469 } Tuesday, February 8, 2011
  • 40. >  db.subjects.find({2008:  {$ne:  null}})       {  "_id"  :  ObjectId("4d50c6c32472473e54122d29"),  "name"  :  "Subject  A" {  "_id"  :  ObjectId("4d50c6d92472473e54122d2a"),  "name"  :  "Subject  B" Tuesday, February 8, 2011
  • 41. Schemaless Joy • Transforming data models is a delight • Formless data isn’t awkward • Arbitrary embedding is awesome Tuesday, February 8, 2011
  • 43. Schemaless Joy • Transforming data models is a delight • Formless data isn’t awkward • Arbitrary embedding is awesome • Building to work with schemaless data can lead to some really powerful app concepts Tuesday, February 8, 2011
  • 44. ...but be wary. Going nuts will create headaches for you. Tuesday, February 8, 2011
  • 46. Schemaless Pain • Weird app behavior Tuesday, February 8, 2011
  • 47. Schemaless Pain • Weird app behavior • Huge, long-running data transformations Tuesday, February 8, 2011
  • 48. Schemaless Pain • Weird app behavior • Huge, long-running data transformations • Annoying data transforms for development env’s Tuesday, February 8, 2011
  • 49. Schemaless Pain • Weird app behavior • Huge, long-running data transformations • Annoying data transforms for development env’s • Difficult to version data models Tuesday, February 8, 2011
  • 50. Lesson 4 Dig deep. Tuesday, February 8, 2011
  • 51. >  db.runCommand({"serverStatus"  :  1}) {   "version"  :  "1.4.3",   "uptime"  :  96,   "localTime"  :  "Thu  Nov  18  2010  01:49:38   GMT-­‐0500  (EST)",   "globalLock"  :  {     "totalTime"  :  96005290,     "lockTime"  :  174040,     "ratio"  :  0.0018128167729090762   },   "mem"  :  {     "bits"  :  64,     "resident"  :  2,     "virtual"  :  2396,     "supported"  :  true,     "mapped"  :  0   },   "connections"  :  {     "current"  :  1,     "available"  :  19999   }, Tuesday, February 8, 2011   "extra_info"  :  {
  • 52. "opcounters"  :  {    "insert"  :  0,    "query"  :  1,    "update"  :  0,    "delete"  :  0,    "getmore"  :  0,    "command"  :  3 } Tuesday, February 8, 2011
  • 53. "connections"  :  {    "current"  :  1,    "available"  :  19999 } Tuesday, February 8, 2011
  • 54. Jeremy-­‐McAnallys-­‐MacBook-­‐Pro:~  jeremymcanally$  mongostat connected  to:  127.0.0.1 insert/s  query/s  update/s  delete/s  getmore/s  command/s  mapped    vsize        res  %  locked  %  idx  miss    conn                0              0                0                0                  0                  1            0      2396            3                0                    0          1                0              0                0                0                  0                  1            0      2396            3                0                    0          1                0              0                0                0                  0                  1            0      2396            3                0                    0          1                0              0                0                0                  0                  1            0      2396            3                0                    0          1                0              0                0                0                  0                  1            0      2396            3                0                    0          1                0              0                0                0                  0                  1            0      2396            3                0                    0          1                0              0                0                0                  0                  1            0      2396            3                0                    0          1                0              0                0                0                  0                  1            0      2396            3                0                    0          1   Tuesday, February 8, 2011
  • 56. db._adminCommand({  diagLogging  :  1  }) Tuesday, February 8, 2011
  • 57. db.currentOp() {  inprog:  [  {  "opid"  :  35  ,  "op"  :  "query"  ,  "ns"  :   "fundb.parties"  ,                            "query"  :  "{  score  :  1.0  }"  ,  "inLock"  :  1  }                    ] } Tuesday, February 8, 2011
  • 58. >  db.oplog.$main.find() {  "ts"  :  {  "t"  :  1290063566000,  "i"  :  1  },  "op"  :  "i",  "ns"  :  "ming {  "ts"  :  {  "t"  :  1290063569000,  "i"  :  1  },  "op"  :  "n",  "ns"  :  "",  " {  "ts"  :  {  "t"  :  1290063579000,  "i"  :  1  },  "op"  :  "n",  "ns"  :  "",  " {  "ts"  :  {  "t"  :  1290063581000,  "i"  :  1  },  "op"  :  "i",  "ns"  :  "ming {  "ts"  :  {  "t"  :  1290063581000,  "i"  :  2  },  "op"  :  "i",  "ns"  :  "ming Tuesday, February 8, 2011
  • 59. {  "ts"  :      {  "t"  :  1290063566000,          "i"  :  1      },      "op"  :  "i",      "ns"  :  "ming.foo",      "o"  :  {            "_id"  :  ObjectId("4ce4ceceabb1b65158000001"),            "field"  :  2      }   } Tuesday, February 8, 2011
  • 60. That’s all I got. Questions? Tuesday, February 8, 2011