SlideShare a Scribd company logo
Building Your First Application in Java
    Bryan Reinero
    Bryan.reinero@10gen.com
    September 2012




1
      High performance
      Highly available
      Easily scalable
      Easy to use
      Feature rich


                                                Document store


©2012 Jaspersoft Corporation. Proprietary and
Confidential                                         2
Data Model

      A Mongo system holds a set of databases
      A database holds a set of collections
      A collection holds a set of documents
      A document is a set of fields
      A field is a key-value pair
      A key is a name (string)
      A value is a
                   basic type like string, integer, float, timestamp, binary, etc.,
                   a document, or
                   an array of values



©2012 Jaspersoft Corporation. Proprietary and
Confidential                                       3
High Availability: Replica Sets


 Initialize -> Election
 Primary + data replication from primary to secondary


                Node 1                                       Node 2
               Secondary                        Heartbeat   Secondary



                                                Node 3
                                                Primary
                               Replication                    Replication


©2012 Jaspersoft Corporation. Proprietary and
Confidential                                      4
High Availability: Failure


 Primary down/network failure
 Automatic election of new primary if majority exists

                                                Primary Election
                Node 1                                              Node 2
               Secondary                          Heartbeat        Secondary



                                                   Node 3
                                                   Primary


©2012 Jaspersoft Corporation. Proprietary and
Confidential                                         5
High Availability: Failover


 New primary elected
 Replication established from new primary


                Node 1                                       Node 2
               Secondary                        Heartbeat   Secondary



                                                Node 3
                                                Primary


©2012 Jaspersoft Corporation. Proprietary and
Confidential                                      6
Durability

      Fire and forget
      Wait for error
      Wait for journal sync
      Wait for fsync
      Wait for replication




©2012 Jaspersoft Corporation. Proprietary and
Confidential                                    7
Read Preferences


      PRIMARY
      PRIMARY PREFERRED
      SECONDARY
      SECONDARY PREFERRED
      NEAREST




©2012 Jaspersoft Corporation. Proprietary and
Confidential                                    8
Let’s build a location based surf reporting app!




©2012 Jaspersoft Corporation. Proprietary and
Confidential                                    9
Let’s build a location based surf reporting app!




• Report current conditions
Let’s build a location based surf reporting app!




• Report current conditions
• Get current local conditions
Let’s build a location based surf reporting app!




• Report current conditions
• Get current local conditions
• Determine best conditions per beach
Document Structure
{
     "_id" : ObjectId("504ceb3d30042d707af96fef"),
     "reporter" : "test",
     "location" : {
               "coordinates" : [
                          -122.477222,
                          37.810556
               ],
               "name" : "Fort Point"
     },
     "conditions" : {
               "height" : 0,
               "period" : 9,
               "rating" : 1
     },
     "date" : ISODate("2011-11-16T20:17:17.277Z")
}
Document Structure
{
     "_id" : ObjectId("504ceb3d30042d707af96fef"),   Primary Key,
     "reporter" : "test",
                                                     Unique,
     "location" : {
               "coordinates" : [                     Auto-indexed
                          -122.477222,
                          37.810556
               ],
               "name" : "Fort Point"
     },
     "conditions" : {
               "height" : 0,
               "period" : 9,
               "rating" : 1
     },
     "date" : ISODate("2011-11-16T20:17:17.277Z")
}
Document Structure
{
     "_id" : ObjectId("504ceb3d30042d707af96fef"),      Primary Key,
     "reporter" : "test",
                                                        Unique,
     "location" : {
               "coordinates" : [                        Autoindexed
                          -122.477222,
                          37.810556
               ],                                    Compound Index,
               "name" : "Fort Point"                 Geospacial
     },
     "conditions" : {
               "height" : 0,
               "period" : 9,
               "rating" : 1
     },
     "date" : ISODate("2011-11-16T20:17:17.277Z")
}
Document Structure
{
     "_id" : ObjectId("504ceb3d30042d707af96fef"),     Primary Key,
     "reporter" : "test",
                                                       Unique,
     "location" : {
               "coordinates" : [                       Autoindexed
                          -122.477222,
                          37.810556
               ],                                    Compound Index,
               "name" : "Fort Point"                 Geospacial
     },
     "conditions" : {
               "height" : 0,
               "period" : 9,
               "rating" : 1
     },                                                 Indexed for
     "date" : ISODate("2011-11-16T20:17:17.277Z")       Time-To-Live
}
Get local surf conditions

  db.reports.find(
            {
            "location.coordinates" : { $near : [-122, 37] ,
            $maxDistance : 0.9},
            date : { $gte : new Date(2012, 8, 9)}
            },
            {"date" : 1, "location.name" :1, _id : 0, "conditions" :1}
  ).sort({"conditions.rating" : -1})
Get local surf conditions

  db.reports.find(
            {
            "location.coordinates" : { $near : [-122, 37] ,
            $maxDistance : 0.9},
            date : { $gte : new Date(2012, 8, 9)}
            },
            {"date" : 1, "location.name" :1, _id : 0, "conditions" :1}
  ).sort({"conditions.rating" : -1})

  • Get local reports
Get local surf conditions

  db.reports.find(
            {
            "location.coordinates" : { $near : [-122, 37] ,
            $maxDistance : 0.9},
            date : { $gte : new Date(2012, 8, 9)}
            },
            {"date" : 1, "location.name" :1, _id : 0, "conditions" :1}
  ).sort({"conditions.rating" : -1})

  • Get local reports
  • Get today’s reports
Get local surf conditions

  db.reports.find(
            {
            "location.coordinates" : { $near : [-122, 37] ,
            $maxDistance : 0.9},
            date : { $gte : new Date(2012, 8, 9)}
            },
            {"location.name" :1, _id : 0, "conditions" :1}
  ).sort({"conditions.rating" : -1})

  • Get local reports
  • Get today’s reports
  • Return only the relevant info
Get local surf conditions

  db.reports.find(
            {
            "location.coordinates" : { $near : [-122, 37] ,
            $maxDistance : 0.9},
            date : { $gte : new Date(2012, 8, 9)}
            },
            {"location.name" :1, _id : 0, "conditions" :1}
  ).sort({"conditions.rating" : -1})

  •   Get local reports
  •   Get today’s reports
  •   Return only the relevant info
  •   Show me the best surf first
Results

{ "location" : { "name" : "Montara" }, "conditions" : { "height" : 6, "period" : 20, "rating" : 5 } }
{ "location" : { "name" : "Maverick's" }, "conditions" : { "height" : 5, "period" : 13, "rating" : 3 } }
{ "location" : { "name" : "Maverick's" }, "conditions" : { "height" : 3, "period" : 15, "rating" : 3 } }
{ "location" : { "name" : "Maverick's" }, "conditions" : { "height" : 3, "period" : 16, "rating" : 2 } }
{ "location" : { "name" : "Montara" }, "conditions" : { "height" : 0, "period" : 8, "rating" : 1 } }
{ "location" : { "name" : "Linda Mar" }, "conditions" : { "height" : 3, "period" : 10, "rating" : 1 } }
{ "location" : { "name" : "Sharp Park" }, "conditions" : { "height" : 1, "period" : 15, "rating" : 1 } }
{ "location" : { "name" : "Sharp Park" }, "conditions" : { "height" : 5, "period" : 6, "rating" : 1 } }
{ "location" : { "name" : "South Ocean Beach" }, "conditions" : { "height" : 1, "period" : 6, "rating" : 1 } }
{ "location" : { "name" : "South Ocean Beach" }, "conditions" : { "height" : 0, "period" : 10, "rating" : 1 } }
{ "location" : { "name" : "South Ocean Beach" }, "conditions" : { "height" : 4, "period" : 6, "rating" : 1 } }
{ "location" : { "name" : "South Ocean Beach" }, "conditions" : { "height" : 0, "period" : 14, "rating" : 1 } }
Scaling

 Sharding is the partitioning of data among multiple
       machines
      Balancing occurs when the load on any one node grows
       out of proportion




©2012 Jaspersoft Corporation. Proprietary and
Confidential                                         23
Scaling MongoDB



   Sharded cluster


                  MongoDB

              Single Instance
                    Or
                Replica Set
                                  Client
                                Application
The Mechanism of Sharding


                      Complete Data Set

Define Shard Key on Location Name




    Fort Point       Linda Mar Maverick’s Ocean Beach Rockaway
The Mechanism of Sharding


             Chunk                            Chunk

Define Shard Key on Location Name




    Fort Point       Linda Mar Maverick’s Ocean Beach Rockaway
The Mechanism of Sharding


  Chunk         Chunk           Chunk            Chunk




   Fort Point   Linda Mar Maverick’s Ocean Beach Rockaway
The Mechanism of Sharding


  Chunk         Chunk            Chunk            Chunk




   Fort Point   Linda Mar   Maverick’s Ocean BeachRockaway


    Shard 1     Shard 2           Shard 3          Shard 4
The Mechanism of Sharding




       Chu           Chu
       nkc           nkc

       Chu           Chu                        Chu   Chu        Chu   Chu   Chu   Chu
       nkc           nkc                        nkc   nkc        nkc   nkc   nkc   nkc




              Shard 1                           Shard 2           Shard 3    Shard 4




©2012 Jaspersoft Corporation. Proprietary and
Confidential                                                29
The Mechanism of Sharding


                                                         Client
             Query: Linda Mar                          Application



       Chu           Chu
       nkc           nkc

       Chu           Chu                        Chu   Chu        Chu   Chu   Chu   Chu
       nkc           nkc                        nkc   nkc        nkc   nkc   nkc   nkc




              Shard 1                           Shard 2           Shard 3    Shard 4




©2012 Jaspersoft Corporation. Proprietary and
Confidential                                                30
The Mechanism of Sharding


                                                         Client
             Query: Maverick’s                         Application



       Chu           Chu
       nkc           nkc

       Chu           Chu                        Chu   Chu        Chu   Chu   Chu   Chu
       nkc           nkc                        nkc   nkc        nkc   nkc   nkc   nkc




              Shard 1                           Shard 2           Shard 3    Shard 4




©2012 Jaspersoft Corporation. Proprietary and
Confidential                                                31
Analysis Features:
Aggregation Framework




 What are the best conditions for my local beach?
Pipelining Operations


   $match        Match “Linda Mar”

   $project      Only interested in conditions

   $group        Group by rating, averaging
                 wave height and wave period

     $sort       Order by best conditions
Aggregation Framework

 { "aggregate" : "reports" ,
    "pipeline" : [
       { "$match" : { "location.name" : "Linda Mar"}} ,
       { "$project" : { "conditions" : 1}} ,
       { "$group" : {
          "_id" : "$conditions.rating" ,
          "average height" : { "$avg" : "$conditions.height"} ,
          "average period" : { "$avg" : "$conditions.period"}}} ,
       { "$sort" : { "_id" : -1}}
    ]
 }
Aggregation Framework

 { "aggregate" : "reports" ,
    "pipeline" : [
       { "$match" : { "location.name" : "Linda Mar"}} ,
       { "$project" : { "conditions" : 1}} ,
       { "$group" : {
          "_id" : "$conditions.rating" ,
          "average height" : { "$avg" : "$conditions.height"} ,
          "average period" : { "$avg" : "$conditions.period"}}} ,
       { "$sort" : { "_id" : -1}}
    ]
 }


                    Match “Linda Mar”
Aggregation Framework

 { "aggregate" : "reports" ,
    "pipeline" : [
       { "$match" : { "location.name" : "Linda Mar"}} ,
       { "$project" : { "conditions" : 1}} ,
       { "$group" : {
          "_id" : "$conditions.rating" ,
          "average height" : { "$avg" : "$conditions.height"} ,
          "average period" : { "$avg" : "$conditions.period"}}} ,
       { "$sort" : { "_id" : -1}}
    ]
 }


                 Only interested in conditions
Aggregation Framework

 { "aggregate" : "reports" ,
    "pipeline" : [
       { "$match" : { "location.name" : "Linda Mar"}} ,
       { "$project" : { "conditions" : 1}} ,
       { "$group" : {
          "_id" : "$conditions.rating" ,
          "average height" : { "$avg" : "$conditions.height"} ,
          "average period" : { "$avg" : "$conditions.period"}}} ,
       { "$sort" : { "_id" : -1}}
    ]
 }


        Group by rating & average conditions
Aggregation Framework

 { "aggregate" : "reports" ,
    "pipeline" : [
       { "$match" : { "location.name" : "Linda Mar"}} ,
       { "$project" : { "conditions" : 1}} ,
       { "$group" : {
          "_id" : "$conditions.rating" ,
          "average height" : { "$avg" : "$conditions.height"} ,
          "average period" : { "$avg" : "$conditions.period"}}} ,
       { "$sort" : { "_id" : -1}}
    ]
 }


            Show me best conditions first
Other Features…


      Native MapReduce
      Hadoop Connector
      Tagging
      Drivers for all major languages




©2012 Jaspersoft Corporation. Proprietary and
Confidential                                    39
Thanks!

   Office Hours
Thursdays 4-6 pm
555 University Ave.
    Palo Alto

   We’re Hiring !
Bryan.reinero@10gen.com

More Related Content

Viewers also liked (7)

PPTX
MongoDB Roadmap
MongoDB
 
PPT
Giftivo mongodb
MongoDB
 
PPT
A Morning with MongoDB - Helsinki
MongoDB
 
PPTX
Indexing and Query Optimisation
MongoDB
 
PPTX
Webinar: Replication and Replica Sets
MongoDB
 
PPTX
Branf final bringing mongodb into your organization - mongo db-boston2012
MongoDB
 
KEY
Discover MongoDB - Israel
Michael Fiedler
 
MongoDB Roadmap
MongoDB
 
Giftivo mongodb
MongoDB
 
A Morning with MongoDB - Helsinki
MongoDB
 
Indexing and Query Optimisation
MongoDB
 
Webinar: Replication and Replica Sets
MongoDB
 
Branf final bringing mongodb into your organization - mongo db-boston2012
MongoDB
 
Discover MongoDB - Israel
Michael Fiedler
 

Similar to Building your first java application with MongoDB (20)

PPT
MongoDB Basic Concepts
MongoDB
 
PPT
Building web applications with mongo db presentation
Murat Çakal
 
PPTX
First app online conf
MongoDB
 
KEY
Building Your First MongoDB Application
Rick Copeland
 
PDF
Thoughts on Transaction and Consistency Models
iammutex
 
PPTX
Webinar: Building Your First Application with MongoDB
MongoDB
 
PDF
Using Spring with NoSQL databases (SpringOne China 2012)
Chris Richardson
 
PPTX
MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...
MongoDB
 
PPTX
MongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB
 
PDF
Consistency Models in New Generation Databases
iammutex
 
PDF
Consistency-New-Generation-Databases
Roger Xia
 
PDF
MongoDB: What, why, when
Eugenio Minardi
 
PPTX
Webinar: Getting Started with MongoDB - Back to Basics
MongoDB
 
PDF
Nosql hands on handout 04
Krishna Sankar
 
PDF
SDEC2011 NoSQL concepts and models
Korea Sdec
 
PPTX
High-Volume Data Collection and Real Time Analytics Using Redis
cacois
 
PDF
Scaling GIS Data in Non-relational Data Stores
Mike Malone
 
PDF
A Century Of Weather Data - Midwest.io
Randall Hunt
 
KEY
Building your first application w/mongoDB MongoSV2011
Steven Francia
 
PPTX
Java and Mongo
Marcio Mangar
 
MongoDB Basic Concepts
MongoDB
 
Building web applications with mongo db presentation
Murat Çakal
 
First app online conf
MongoDB
 
Building Your First MongoDB Application
Rick Copeland
 
Thoughts on Transaction and Consistency Models
iammutex
 
Webinar: Building Your First Application with MongoDB
MongoDB
 
Using Spring with NoSQL databases (SpringOne China 2012)
Chris Richardson
 
MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...
MongoDB
 
MongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB
 
Consistency Models in New Generation Databases
iammutex
 
Consistency-New-Generation-Databases
Roger Xia
 
MongoDB: What, why, when
Eugenio Minardi
 
Webinar: Getting Started with MongoDB - Back to Basics
MongoDB
 
Nosql hands on handout 04
Krishna Sankar
 
SDEC2011 NoSQL concepts and models
Korea Sdec
 
High-Volume Data Collection and Real Time Analytics Using Redis
cacois
 
Scaling GIS Data in Non-relational Data Stores
Mike Malone
 
A Century Of Weather Data - Midwest.io
Randall Hunt
 
Building your first application w/mongoDB MongoSV2011
Steven Francia
 
Java and Mongo
Marcio Mangar
 
Ad

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
Ad

Recently uploaded (20)

PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PPTX
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PDF
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PPTX
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
Practical Applications of AI in Local Government
OnBoard
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 

Building your first java application with MongoDB

  • 1. Building Your First Application in Java Bryan Reinero [email protected] September 2012 1
  • 2. High performance  Highly available  Easily scalable  Easy to use  Feature rich Document store ©2012 Jaspersoft Corporation. Proprietary and Confidential 2
  • 3. Data Model  A Mongo system holds a set of databases  A database holds a set of collections  A collection holds a set of documents  A document is a set of fields  A field is a key-value pair  A key is a name (string)  A value is a basic type like string, integer, float, timestamp, binary, etc., a document, or an array of values ©2012 Jaspersoft Corporation. Proprietary and Confidential 3
  • 4. High Availability: Replica Sets  Initialize -> Election  Primary + data replication from primary to secondary Node 1 Node 2 Secondary Heartbeat Secondary Node 3 Primary Replication Replication ©2012 Jaspersoft Corporation. Proprietary and Confidential 4
  • 5. High Availability: Failure  Primary down/network failure  Automatic election of new primary if majority exists Primary Election Node 1 Node 2 Secondary Heartbeat Secondary Node 3 Primary ©2012 Jaspersoft Corporation. Proprietary and Confidential 5
  • 6. High Availability: Failover  New primary elected  Replication established from new primary Node 1 Node 2 Secondary Heartbeat Secondary Node 3 Primary ©2012 Jaspersoft Corporation. Proprietary and Confidential 6
  • 7. Durability  Fire and forget  Wait for error  Wait for journal sync  Wait for fsync  Wait for replication ©2012 Jaspersoft Corporation. Proprietary and Confidential 7
  • 8. Read Preferences  PRIMARY  PRIMARY PREFERRED  SECONDARY  SECONDARY PREFERRED  NEAREST ©2012 Jaspersoft Corporation. Proprietary and Confidential 8
  • 9. Let’s build a location based surf reporting app! ©2012 Jaspersoft Corporation. Proprietary and Confidential 9
  • 10. Let’s build a location based surf reporting app! • Report current conditions
  • 11. Let’s build a location based surf reporting app! • Report current conditions • Get current local conditions
  • 12. Let’s build a location based surf reporting app! • Report current conditions • Get current local conditions • Determine best conditions per beach
  • 13. Document Structure { "_id" : ObjectId("504ceb3d30042d707af96fef"), "reporter" : "test", "location" : { "coordinates" : [ -122.477222, 37.810556 ], "name" : "Fort Point" }, "conditions" : { "height" : 0, "period" : 9, "rating" : 1 }, "date" : ISODate("2011-11-16T20:17:17.277Z") }
  • 14. Document Structure { "_id" : ObjectId("504ceb3d30042d707af96fef"), Primary Key, "reporter" : "test", Unique, "location" : { "coordinates" : [ Auto-indexed -122.477222, 37.810556 ], "name" : "Fort Point" }, "conditions" : { "height" : 0, "period" : 9, "rating" : 1 }, "date" : ISODate("2011-11-16T20:17:17.277Z") }
  • 15. Document Structure { "_id" : ObjectId("504ceb3d30042d707af96fef"), Primary Key, "reporter" : "test", Unique, "location" : { "coordinates" : [ Autoindexed -122.477222, 37.810556 ], Compound Index, "name" : "Fort Point" Geospacial }, "conditions" : { "height" : 0, "period" : 9, "rating" : 1 }, "date" : ISODate("2011-11-16T20:17:17.277Z") }
  • 16. Document Structure { "_id" : ObjectId("504ceb3d30042d707af96fef"), Primary Key, "reporter" : "test", Unique, "location" : { "coordinates" : [ Autoindexed -122.477222, 37.810556 ], Compound Index, "name" : "Fort Point" Geospacial }, "conditions" : { "height" : 0, "period" : 9, "rating" : 1 }, Indexed for "date" : ISODate("2011-11-16T20:17:17.277Z") Time-To-Live }
  • 17. Get local surf conditions db.reports.find( { "location.coordinates" : { $near : [-122, 37] , $maxDistance : 0.9}, date : { $gte : new Date(2012, 8, 9)} }, {"date" : 1, "location.name" :1, _id : 0, "conditions" :1} ).sort({"conditions.rating" : -1})
  • 18. Get local surf conditions db.reports.find( { "location.coordinates" : { $near : [-122, 37] , $maxDistance : 0.9}, date : { $gte : new Date(2012, 8, 9)} }, {"date" : 1, "location.name" :1, _id : 0, "conditions" :1} ).sort({"conditions.rating" : -1}) • Get local reports
  • 19. Get local surf conditions db.reports.find( { "location.coordinates" : { $near : [-122, 37] , $maxDistance : 0.9}, date : { $gte : new Date(2012, 8, 9)} }, {"date" : 1, "location.name" :1, _id : 0, "conditions" :1} ).sort({"conditions.rating" : -1}) • Get local reports • Get today’s reports
  • 20. Get local surf conditions db.reports.find( { "location.coordinates" : { $near : [-122, 37] , $maxDistance : 0.9}, date : { $gte : new Date(2012, 8, 9)} }, {"location.name" :1, _id : 0, "conditions" :1} ).sort({"conditions.rating" : -1}) • Get local reports • Get today’s reports • Return only the relevant info
  • 21. Get local surf conditions db.reports.find( { "location.coordinates" : { $near : [-122, 37] , $maxDistance : 0.9}, date : { $gte : new Date(2012, 8, 9)} }, {"location.name" :1, _id : 0, "conditions" :1} ).sort({"conditions.rating" : -1}) • Get local reports • Get today’s reports • Return only the relevant info • Show me the best surf first
  • 22. Results { "location" : { "name" : "Montara" }, "conditions" : { "height" : 6, "period" : 20, "rating" : 5 } } { "location" : { "name" : "Maverick's" }, "conditions" : { "height" : 5, "period" : 13, "rating" : 3 } } { "location" : { "name" : "Maverick's" }, "conditions" : { "height" : 3, "period" : 15, "rating" : 3 } } { "location" : { "name" : "Maverick's" }, "conditions" : { "height" : 3, "period" : 16, "rating" : 2 } } { "location" : { "name" : "Montara" }, "conditions" : { "height" : 0, "period" : 8, "rating" : 1 } } { "location" : { "name" : "Linda Mar" }, "conditions" : { "height" : 3, "period" : 10, "rating" : 1 } } { "location" : { "name" : "Sharp Park" }, "conditions" : { "height" : 1, "period" : 15, "rating" : 1 } } { "location" : { "name" : "Sharp Park" }, "conditions" : { "height" : 5, "period" : 6, "rating" : 1 } } { "location" : { "name" : "South Ocean Beach" }, "conditions" : { "height" : 1, "period" : 6, "rating" : 1 } } { "location" : { "name" : "South Ocean Beach" }, "conditions" : { "height" : 0, "period" : 10, "rating" : 1 } } { "location" : { "name" : "South Ocean Beach" }, "conditions" : { "height" : 4, "period" : 6, "rating" : 1 } } { "location" : { "name" : "South Ocean Beach" }, "conditions" : { "height" : 0, "period" : 14, "rating" : 1 } }
  • 23. Scaling  Sharding is the partitioning of data among multiple machines  Balancing occurs when the load on any one node grows out of proportion ©2012 Jaspersoft Corporation. Proprietary and Confidential 23
  • 24. Scaling MongoDB Sharded cluster MongoDB Single Instance Or Replica Set Client Application
  • 25. The Mechanism of Sharding Complete Data Set Define Shard Key on Location Name Fort Point Linda Mar Maverick’s Ocean Beach Rockaway
  • 26. The Mechanism of Sharding Chunk Chunk Define Shard Key on Location Name Fort Point Linda Mar Maverick’s Ocean Beach Rockaway
  • 27. The Mechanism of Sharding Chunk Chunk Chunk Chunk Fort Point Linda Mar Maverick’s Ocean Beach Rockaway
  • 28. The Mechanism of Sharding Chunk Chunk Chunk Chunk Fort Point Linda Mar Maverick’s Ocean BeachRockaway Shard 1 Shard 2 Shard 3 Shard 4
  • 29. The Mechanism of Sharding Chu Chu nkc nkc Chu Chu Chu Chu Chu Chu Chu Chu nkc nkc nkc nkc nkc nkc nkc nkc Shard 1 Shard 2 Shard 3 Shard 4 ©2012 Jaspersoft Corporation. Proprietary and Confidential 29
  • 30. The Mechanism of Sharding Client Query: Linda Mar Application Chu Chu nkc nkc Chu Chu Chu Chu Chu Chu Chu Chu nkc nkc nkc nkc nkc nkc nkc nkc Shard 1 Shard 2 Shard 3 Shard 4 ©2012 Jaspersoft Corporation. Proprietary and Confidential 30
  • 31. The Mechanism of Sharding Client Query: Maverick’s Application Chu Chu nkc nkc Chu Chu Chu Chu Chu Chu Chu Chu nkc nkc nkc nkc nkc nkc nkc nkc Shard 1 Shard 2 Shard 3 Shard 4 ©2012 Jaspersoft Corporation. Proprietary and Confidential 31
  • 32. Analysis Features: Aggregation Framework What are the best conditions for my local beach?
  • 33. Pipelining Operations $match Match “Linda Mar” $project Only interested in conditions $group Group by rating, averaging wave height and wave period $sort Order by best conditions
  • 34. Aggregation Framework { "aggregate" : "reports" , "pipeline" : [ { "$match" : { "location.name" : "Linda Mar"}} , { "$project" : { "conditions" : 1}} , { "$group" : { "_id" : "$conditions.rating" , "average height" : { "$avg" : "$conditions.height"} , "average period" : { "$avg" : "$conditions.period"}}} , { "$sort" : { "_id" : -1}} ] }
  • 35. Aggregation Framework { "aggregate" : "reports" , "pipeline" : [ { "$match" : { "location.name" : "Linda Mar"}} , { "$project" : { "conditions" : 1}} , { "$group" : { "_id" : "$conditions.rating" , "average height" : { "$avg" : "$conditions.height"} , "average period" : { "$avg" : "$conditions.period"}}} , { "$sort" : { "_id" : -1}} ] } Match “Linda Mar”
  • 36. Aggregation Framework { "aggregate" : "reports" , "pipeline" : [ { "$match" : { "location.name" : "Linda Mar"}} , { "$project" : { "conditions" : 1}} , { "$group" : { "_id" : "$conditions.rating" , "average height" : { "$avg" : "$conditions.height"} , "average period" : { "$avg" : "$conditions.period"}}} , { "$sort" : { "_id" : -1}} ] } Only interested in conditions
  • 37. Aggregation Framework { "aggregate" : "reports" , "pipeline" : [ { "$match" : { "location.name" : "Linda Mar"}} , { "$project" : { "conditions" : 1}} , { "$group" : { "_id" : "$conditions.rating" , "average height" : { "$avg" : "$conditions.height"} , "average period" : { "$avg" : "$conditions.period"}}} , { "$sort" : { "_id" : -1}} ] } Group by rating & average conditions
  • 38. Aggregation Framework { "aggregate" : "reports" , "pipeline" : [ { "$match" : { "location.name" : "Linda Mar"}} , { "$project" : { "conditions" : 1}} , { "$group" : { "_id" : "$conditions.rating" , "average height" : { "$avg" : "$conditions.height"} , "average period" : { "$avg" : "$conditions.period"}}} , { "$sort" : { "_id" : -1}} ] } Show me best conditions first
  • 39. Other Features…  Native MapReduce  Hadoop Connector  Tagging  Drivers for all major languages ©2012 Jaspersoft Corporation. Proprietary and Confidential 39
  • 40. Thanks! Office Hours Thursdays 4-6 pm 555 University Ave. Palo Alto We’re Hiring ! [email protected]