SlideShare a Scribd company logo
MongoDB
                      JBoss User Group Brno




                                      dagi@gooddata.com

Thursday 3 May 2012
About me
                      •   Roman Pichlík

                      •   GoodData

                      •   CZJUG

                      •   CZ Podcast

                      •   Follow me on Twitter

                          •   @_dagi



Thursday 3 May 2012
Agenda

                      • What’s wrong...
                      • Demo
                      • Using MongoDB in Java
                      • MongoDB deployment in GoodData
                      • Q&A

Thursday 3 May 2012
A typical java app with
                             RDBMS
                                      Web Layer
                         Domain
                                  Business Logic Layer
                         model
                                   Data Access Layer




Thursday 3 May 2012
A typical java app with
                             RDBMS
                                      Web Layer
                         Domain
                                  Business Logic Layer
                         model
                                   Data Access Layer




Thursday 3 May 2012
A typical java app with
                             RDBMS
                                                        Web Layer
                             Domain
                                                    Business Logic Layer
                             model
      am
            eta
               dat
                                                     Data Access Layer
                  a fo
                      rm
                        app
                            ing
                                to
                                     RD
                                       BM
                                         S sc
                                             hem
                                                a




Thursday 3 May 2012
A typical java app with
                             RDBMS
                                                        Web Layer
                             Domain
                                                    Business Logic Layer
                             model
      am
            eta
               dat
                                                     Data Access Layer
                  a fo
                      rm
                        app                                                                      al
                            ing                                                          e lation
                                to                                               b ject/R sa
                                     RD                                  ic for O ice ver
                                       BM                           k mag on and v
                                         S sc
                                             hem              a blac versi
                                                a                   con




Thursday 3 May 2012
A typical java app with
                             RDBMS
                                                        Web Layer
                             Domain
                                                    Business Logic Layer
                             model
      am
            eta
               dat
                                                     Data Access Layer
                  a fo
                      rm
                        app                                                                      al
                            ing                                                          e lation
                                to                                               b ject/R sa
                                     RD                                  ic for O ice ver
                                       BM                           k mag on and v
                                         S sc
                                             hem              a blac versi
                                                a                   con

                                                                         and transactions...


Thursday 3 May 2012
Data Access Layer




Thursday 3 May 2012

It’s not only complicated on this picture -> required 3rd party libraries on classpath
Data Access Layer
                                   CRUD interface




Thursday 3 May 2012

It’s not only complicated on this picture -> required 3rd party libraries on classpath
Data Access Layer
                                   CRUD interface

                      Persistence context logic (queries, merge...)




Thursday 3 May 2012

It’s not only complicated on this picture -> required 3rd party libraries on classpath
Data Access Layer
                                   CRUD interface

                      Persistence context logic (queries, merge...)

                                  Spring ORM Bridge




Thursday 3 May 2012

It’s not only complicated on this picture -> required 3rd party libraries on classpath
Data Access Layer
                                   CRUD interface

                      Persistence context logic (queries, merge...)

                                  Spring ORM Bridge

                           ORM framework (Hibernate/JPA)



Thursday 3 May 2012

It’s not only complicated on this picture -> required 3rd party libraries on classpath
Data Access Layer
                                   CRUD interface

                      Persistence context logic (queries, merge...)
  Why the hell it’s so complicated?!
                                  Spring ORM Bridge

                           ORM framework (Hibernate/JPA)



Thursday 3 May 2012

It’s not only complicated on this picture -> required 3rd party libraries on classpath
Abstraction faux pas

                      • We get used to live/think in Object world
                      • We store data in RDBMS world
                      • We build a bridge between Object/
                        RDBMS worlds
                      • The bridge (ORM) is very complicated

Thursday 3 May 2012

How many of you know patterns like Open Session in View, DTO?
How many of you know the difference between first and second level cache?
How many of you know the difference between Session#load and Session#get method?
Time for MongoDB



Thursday 3 May 2012
MongoDB
                      • Document oriented database
                      • Schema less
                      • Driver API
                      • NoSQL but Query friendly
                      • Open source
                       • AGPL server, Apache 2.0 driver
Thursday 3 May 2012
Data organization




Thursday 3 May 2012

document - JSON
schemaless (documents, fields)
Data organization
                                   RDBMS
                                      table
                                        Fruit
                                         id
                                       weight
                                       color
                                   discriminator
                                      country
                                     curvature




Thursday 3 May 2012

document - JSON
schemaless (documents, fields)
Data organization
                 MongoDB                RDBMS
                      collection           table
                        Fruit                Fruit
                      Document                id
                                            weight
                                            color
                                        discriminator
                                           country
                                          curvature




Thursday 3 May 2012

document - JSON
schemaless (documents, fields)
Data organization
                 MongoDB                RDBMS
                      collection           table
                        Fruit                Fruit
                      Document                id
                                            weight
                                            color
                                        discriminator
                                           country
                                          curvature




Thursday 3 May 2012

document - JSON
schemaless (documents, fields)
Data organization
                 MongoDB                                       RDBMS
                      collection                                      table
                        Fruit                                         Fruit
                      Document                                         id
                                                                     weight
                                                                     color
                                                                 discriminator
                                                                    country
                                                                   curvature


                                         id   discriminator   color    weight    country   curvature
                                   row   1       apple        red       10         cz        null
                                         2      banana        null      5.1        br          3




Thursday 3 May 2012

document - JSON
schemaless (documents, fields)
Data organization
                 MongoDB                                           RDBMS
                      collection                                          table
                        Fruit                                             Fruit
                      Document                                             id
                                                                         weight
                      document
                                                                         color
               {                                                     discriminator
                  "_id":"1",                                            country
                  "apple":{                                            curvature
                     "weight":10,
                     "country":"cz",
                     "color":"red"           id   discriminator   color    weight    country   curvature
                  }
               }                       row   1       apple        red       10         cz        null
                                             2      banana        null      5.1        br          3
               {
                  "_id":"2",
                  "banana":{
                     "weight":5.1,
                     "country":"br",
                     "curvature":3
                  }
               }

Thursday 3 May 2012

document - JSON
schemaless (documents, fields)
Data organization
                 MongoDB                                           RDBMS
                      collection                                          table
                        Fruit                                             Fruit
                      Document                                             id
                                                                         weight
                      document
                                                                         color
               {                                                     discriminator
                  "_id":"1",                                            country
                  "apple":{                                            curvature
                     "weight":10,
                     "country":"cz",
                     "color":"red"           id   discriminator   color    weight    country   curvature
                  }
               }                       row   1       apple        red       10         cz        null
                                             2      banana        null      5.1        br          3
               {
                  "_id":"2",
                  "banana":{
                     "weight":5.1,
                     "country":"br",
                     "curvature":3
                  }
               }

Thursday 3 May 2012

document - JSON
schemaless (documents, fields)
Data organization
                 MongoDB                                                  RDBMS
                      collection                                                 table
                        Fruit                                                    Fruit
                      Document                                                    id
                                                                                weight
                      document
                                                                                color
               {                                                            discriminator
                  "_id":"1",                                                   country
                  "apple":{                                                   curvature
                     "weight":10,
                     "country":"cz",
                     "color":"red"                  id   discriminator   color    weight    country   curvature
                  }
               }                              row   1       apple        red       10         cz        null
                                                    2      banana        null      5.1        br          3
               {
                  "_id":"2",                              column
                  "banana":{
                     "weight":5.1,     field
                     "country":"br",
                     "curvature":3
                  }
               }

Thursday 3 May 2012

document - JSON
schemaless (documents, fields)
Fruit demo :-)



Thursday 3 May 2012
> use fruitdb
                                    change/create DB
  switched to db fruitdb
                                          insert document
  > db.createCollection("fruit");
  { "ok" : 1 }

  > db.fruit.insert({apple:{weight:10, country:"cz", color:"red"}});

  > db.fruit.findOne();                get first document
  { "_id" : ObjectId("4fa0f21591d1fb43c578fa26"), "apple" : { "color" :
  "red", "country" : "cz", "weight" : 10 } }

  > db.fruit.insert({banana:{weight:5.1, country: "br", curvature:3}});

  > db.fruit.update({"apple.color":"green"}, {$set:
  {"apple.color":"red"}});                      update document
  > db.fruit.remove({"_id":"4fa0f3a791d1fb43c578fa27"})

  > db.fruit.find({"apple.color":"red"});     remove document
  { "_id" : ObjectId("4fa0f21591d1fb43c578fa26"), "apple" : { "color" :
  "red", "country" : "cz", "weight" : 10 } }

                                                  find document
Thursday 3 May 2012
Using MongoDB in Java
                  MongoDB                      Java Application
                        BSON                         Web Layer
                                      Domain
                      JSON document            Business Logic Layer
         {                            model
            "_id":"...",
            "apple":{
                                                Data Access Layer
               "weight":10,
               "country":"cz",
               "color":"red"
                                       BSON API          Auth.
            }
         }
                                             MongoDB driver
                                        Failover     Connectivity

Thursday 3 May 2012
Using MongoDB in Java
                      Mongo m = new Mongo("localhost" , 27017 );

                      DB db = m.getDB( "fruitdb" );
                      DBCollection coll = db.getCollection("fruit");

                      BasicDBObject doc = new BasicDBObject();
                      BasicDBObject apple = new BasicDBObject();
                      apple.put("weight", 10);
                      apple.put("country", "cz");
                      apple.put("color", "red");
                      doc.put("apple", apple);

                      fruit.insert(doc);




Thursday 3 May 2012
Sweet MongoDB
                      •   Thin Data Access Layer

                          •   No magic behind the
                              scene

                      •   Flexible

                          •   schemaless

                          •   new document types

                          •   new collections

                          •   No Alter DDL
Thursday 3 May 2012
Architecture impact
                      • No transactions
                       • only atomic update on document level
                       • atomic FindAndUpdate operation
                      • No constraints
                       • application logic handles data
                          inconsistency
                      • Self sufficient documents over Joins
Thursday 3 May 2012
                       • redundancy
MongoDB cluster in GoodData




                                                  Sync. write, Master + Slave
                      •   GoodData platform




                                                                                                          No slave reads
                          hosted on Amazon WS                                           Client

                      •   3-node

                      •   Journal enabled                                               Master
                      •   EBS used for data
                                                                                    replication
                          •   backup/restore
                                                                                Slave             Slave
                      •   Application specific
                          backup/restore

Thursday 3 May 2012

* Master elected automatically on start or when the previous one goes down
* Master writes to journal -> Ops log replicated to slaves
Thank you

                      •   Join us and work with MongoDB ;-)

                      •   http://www.gooddata.com/about/careers

                      •   Q&A




Thursday 3 May 2012

More Related Content

PPT
Kuldeep presentation ppt
PDF
MongoDB training for java software engineers
PPTX
MongoDB 3.4 webinar
PPT
Four Problems You Run into When DIY-ing a “Big Data” Analytics System
PDF
High performance database applications with pure query and ibm data studio.ba...
PDF
Nosql from java developer pov
PPT
Jdbc Dao it-slideshares.blogspot.com
PDF
SQL? NoSQL? NewSQL?!? What’s a Java developer to do? - JDC2012 Cairo, Egypt
Kuldeep presentation ppt
MongoDB training for java software engineers
MongoDB 3.4 webinar
Four Problems You Run into When DIY-ing a “Big Data” Analytics System
High performance database applications with pure query and ibm data studio.ba...
Nosql from java developer pov
Jdbc Dao it-slideshares.blogspot.com
SQL? NoSQL? NewSQL?!? What’s a Java developer to do? - JDC2012 Cairo, Egypt

Similar to MongoDB for Java Developers (20)

PPTX
SQL Data Service Overview
PPTX
Big Data (NJ SQL Server User Group)
PPTX
Easy Data Object Relational Mapping Tool
PDF
MapReduce and Its Discontents
PDF
SQL, NoSQL, NewSQL? What's a developer to do?
PDF
Treasure Data: Big Data Analytics on Heroku
PDF
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
KEY
Appengine Nljug
PPT
Object Relational Mapping with LINQ To SQL
PDF
LinkedIn Data Infrastructure Slides (Version 2)
PPTX
Anti-social Databases
PDF
Five steps perform_2013
PDF
Google Devfest 2009 Argentina - Intro to Appengine
PPTX
An Introduction to Big Data, NoSQL and MongoDB
PPTX
Polyglot persistence with no sql
PPTX
Jornadas tecnologicas2012mvvm
PDF
02introduction
PDF
What Drove Wordnik Non-Relational?
PPTX
Lets focus on business value
PDF
Unified big data architecture
SQL Data Service Overview
Big Data (NJ SQL Server User Group)
Easy Data Object Relational Mapping Tool
MapReduce and Its Discontents
SQL, NoSQL, NewSQL? What's a developer to do?
Treasure Data: Big Data Analytics on Heroku
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
Appengine Nljug
Object Relational Mapping with LINQ To SQL
LinkedIn Data Infrastructure Slides (Version 2)
Anti-social Databases
Five steps perform_2013
Google Devfest 2009 Argentina - Intro to Appengine
An Introduction to Big Data, NoSQL and MongoDB
Polyglot persistence with no sql
Jornadas tecnologicas2012mvvm
02introduction
What Drove Wordnik Non-Relational?
Lets focus on business value
Unified big data architecture
Ad

More from Roman Pichlík (15)

PDF
Cynycal software
PDF
App Design Architecture
PDF
Spring MVC
PDF
Spring Transactions
PDF
Spring Testing
PDF
Spring J2EE
PDF
Spring ioc-advanced
PDF
Spring ioc
PDF
Spring introduction
PDF
Spring integration
PDF
Spring dao
PDF
Spring aop
PDF
Spring Web Services
PDF
Spring framework - J2EE S Lidskou Tvari
PPTX
Dependency Injection Frameworky
Cynycal software
App Design Architecture
Spring MVC
Spring Transactions
Spring Testing
Spring J2EE
Spring ioc-advanced
Spring ioc
Spring introduction
Spring integration
Spring dao
Spring aop
Spring Web Services
Spring framework - J2EE S Lidskou Tvari
Dependency Injection Frameworky
Ad

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
Tartificialntelligence_presentation.pptx
PDF
STKI Israel Market Study 2025 version august
PDF
Hybrid model detection and classification of lung cancer
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Getting started with AI Agents and Multi-Agent Systems
Programs and apps: productivity, graphics, security and other tools
Zenith AI: Advanced Artificial Intelligence
Developing a website for English-speaking practice to English as a foreign la...
Tartificialntelligence_presentation.pptx
STKI Israel Market Study 2025 version august
Hybrid model detection and classification of lung cancer
WOOl fibre morphology and structure.pdf for textiles
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Final SEM Unit 1 for mit wpu at pune .pptx
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
O2C Customer Invoices to Receipt V15A.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
A comparative study of natural language inference in Swahili using monolingua...
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
1 - Historical Antecedents, Social Consideration.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
TLE Review Electricity (Electricity).pptx
Getting started with AI Agents and Multi-Agent Systems

MongoDB for Java Developers

  • 1. MongoDB JBoss User Group Brno dagi@gooddata.com Thursday 3 May 2012
  • 2. About me • Roman Pichlík • GoodData • CZJUG • CZ Podcast • Follow me on Twitter • @_dagi Thursday 3 May 2012
  • 3. Agenda • What’s wrong... • Demo • Using MongoDB in Java • MongoDB deployment in GoodData • Q&A Thursday 3 May 2012
  • 4. A typical java app with RDBMS Web Layer Domain Business Logic Layer model Data Access Layer Thursday 3 May 2012
  • 5. A typical java app with RDBMS Web Layer Domain Business Logic Layer model Data Access Layer Thursday 3 May 2012
  • 6. A typical java app with RDBMS Web Layer Domain Business Logic Layer model am eta dat Data Access Layer a fo rm app ing to RD BM S sc hem a Thursday 3 May 2012
  • 7. A typical java app with RDBMS Web Layer Domain Business Logic Layer model am eta dat Data Access Layer a fo rm app al ing e lation to b ject/R sa RD ic for O ice ver BM k mag on and v S sc hem a blac versi a con Thursday 3 May 2012
  • 8. A typical java app with RDBMS Web Layer Domain Business Logic Layer model am eta dat Data Access Layer a fo rm app al ing e lation to b ject/R sa RD ic for O ice ver BM k mag on and v S sc hem a blac versi a con and transactions... Thursday 3 May 2012
  • 9. Data Access Layer Thursday 3 May 2012 It’s not only complicated on this picture -> required 3rd party libraries on classpath
  • 10. Data Access Layer CRUD interface Thursday 3 May 2012 It’s not only complicated on this picture -> required 3rd party libraries on classpath
  • 11. Data Access Layer CRUD interface Persistence context logic (queries, merge...) Thursday 3 May 2012 It’s not only complicated on this picture -> required 3rd party libraries on classpath
  • 12. Data Access Layer CRUD interface Persistence context logic (queries, merge...) Spring ORM Bridge Thursday 3 May 2012 It’s not only complicated on this picture -> required 3rd party libraries on classpath
  • 13. Data Access Layer CRUD interface Persistence context logic (queries, merge...) Spring ORM Bridge ORM framework (Hibernate/JPA) Thursday 3 May 2012 It’s not only complicated on this picture -> required 3rd party libraries on classpath
  • 14. Data Access Layer CRUD interface Persistence context logic (queries, merge...) Why the hell it’s so complicated?! Spring ORM Bridge ORM framework (Hibernate/JPA) Thursday 3 May 2012 It’s not only complicated on this picture -> required 3rd party libraries on classpath
  • 15. Abstraction faux pas • We get used to live/think in Object world • We store data in RDBMS world • We build a bridge between Object/ RDBMS worlds • The bridge (ORM) is very complicated Thursday 3 May 2012 How many of you know patterns like Open Session in View, DTO? How many of you know the difference between first and second level cache? How many of you know the difference between Session#load and Session#get method?
  • 17. MongoDB • Document oriented database • Schema less • Driver API • NoSQL but Query friendly • Open source • AGPL server, Apache 2.0 driver Thursday 3 May 2012
  • 18. Data organization Thursday 3 May 2012 document - JSON schemaless (documents, fields)
  • 19. Data organization RDBMS table Fruit id weight color discriminator country curvature Thursday 3 May 2012 document - JSON schemaless (documents, fields)
  • 20. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight color discriminator country curvature Thursday 3 May 2012 document - JSON schemaless (documents, fields)
  • 21. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight color discriminator country curvature Thursday 3 May 2012 document - JSON schemaless (documents, fields)
  • 22. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight color discriminator country curvature id discriminator color weight country curvature row 1 apple red 10 cz null 2 banana null 5.1 br 3 Thursday 3 May 2012 document - JSON schemaless (documents, fields)
  • 23. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight document color { discriminator    "_id":"1", country    "apple":{ curvature       "weight":10,       "country":"cz",       "color":"red" id discriminator color weight country curvature    } } row 1 apple red 10 cz null 2 banana null 5.1 br 3 {    "_id":"2",    "banana":{       "weight":5.1,       "country":"br",       "curvature":3    } } Thursday 3 May 2012 document - JSON schemaless (documents, fields)
  • 24. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight document color { discriminator    "_id":"1", country    "apple":{ curvature       "weight":10,       "country":"cz",       "color":"red" id discriminator color weight country curvature    } } row 1 apple red 10 cz null 2 banana null 5.1 br 3 {    "_id":"2",    "banana":{       "weight":5.1,       "country":"br",       "curvature":3    } } Thursday 3 May 2012 document - JSON schemaless (documents, fields)
  • 25. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight document color { discriminator    "_id":"1", country    "apple":{ curvature       "weight":10,       "country":"cz",       "color":"red" id discriminator color weight country curvature    } } row 1 apple red 10 cz null 2 banana null 5.1 br 3 {    "_id":"2", column    "banana":{       "weight":5.1, field       "country":"br",       "curvature":3    } } Thursday 3 May 2012 document - JSON schemaless (documents, fields)
  • 27. > use fruitdb change/create DB switched to db fruitdb insert document > db.createCollection("fruit"); { "ok" : 1 } > db.fruit.insert({apple:{weight:10, country:"cz", color:"red"}}); > db.fruit.findOne(); get first document { "_id" : ObjectId("4fa0f21591d1fb43c578fa26"), "apple" : { "color" : "red", "country" : "cz", "weight" : 10 } } > db.fruit.insert({banana:{weight:5.1, country: "br", curvature:3}}); > db.fruit.update({"apple.color":"green"}, {$set: {"apple.color":"red"}}); update document > db.fruit.remove({"_id":"4fa0f3a791d1fb43c578fa27"}) > db.fruit.find({"apple.color":"red"}); remove document { "_id" : ObjectId("4fa0f21591d1fb43c578fa26"), "apple" : { "color" : "red", "country" : "cz", "weight" : 10 } } find document Thursday 3 May 2012
  • 28. Using MongoDB in Java MongoDB Java Application BSON Web Layer Domain JSON document Business Logic Layer { model    "_id":"...",    "apple":{ Data Access Layer       "weight":10,       "country":"cz",       "color":"red" BSON API Auth.    } } MongoDB driver Failover Connectivity Thursday 3 May 2012
  • 29. Using MongoDB in Java Mongo m = new Mongo("localhost" , 27017 ); DB db = m.getDB( "fruitdb" ); DBCollection coll = db.getCollection("fruit"); BasicDBObject doc = new BasicDBObject(); BasicDBObject apple = new BasicDBObject(); apple.put("weight", 10); apple.put("country", "cz"); apple.put("color", "red"); doc.put("apple", apple); fruit.insert(doc); Thursday 3 May 2012
  • 30. Sweet MongoDB • Thin Data Access Layer • No magic behind the scene • Flexible • schemaless • new document types • new collections • No Alter DDL Thursday 3 May 2012
  • 31. Architecture impact • No transactions • only atomic update on document level • atomic FindAndUpdate operation • No constraints • application logic handles data inconsistency • Self sufficient documents over Joins Thursday 3 May 2012 • redundancy
  • 32. MongoDB cluster in GoodData Sync. write, Master + Slave • GoodData platform No slave reads hosted on Amazon WS Client • 3-node • Journal enabled Master • EBS used for data replication • backup/restore Slave Slave • Application specific backup/restore Thursday 3 May 2012 * Master elected automatically on start or when the previous one goes down * Master writes to journal -> Ops log replicated to slaves
  • 33. Thank you • Join us and work with MongoDB ;-) • http://www.gooddata.com/about/careers • Q&A Thursday 3 May 2012