SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
Mongo + Java = Jongo
                          Mongo and Java made easy !




                            by @karesti - MongoSV 2012

mardi 4 décembre 12
Agile Developer
                                      MongoDB User
                       @karesti      MongoDB Master

                      Katia Aresti



mardi 4 décembre 12
Back on 2010 ...




mardi 4 décembre 12
{mongo : "awesome"}
mardi 4 décembre 12
DBObject API



                      REST Web
                       Services
                      Search of
                        POI-s




        {DBObject : "not bad, not awesome"}

mardi 4 décembre 12
Back on 2010 ...




                       Morphia ?
mardi 4 décembre 12
Morphia
                                JPA-LIKE




mardi 4 décembre 12
So ...
                      •   Morphia is great, good work !

                      •   But : Need to learn another API => Mongo, Java Driver,
                          Morphia

                      •   But : JPA Like -> Mongo Paradigm is not JPA / Hibernate

                      •   Morphia is comming to Java Driver ?

                      •   Final choice :

                          •   Morphia for the Java - DBObject Mapping


mardi 4 décembre 12
Late 2011 ...




mardi 4 décembre 12
@bguerout

                                           Jongo
                                                                @amsellemyves


                      •   What’s Jongo ?

                          • ODM on top of the Java Driver
                          • Jackson and BSON4Jackson for (Un)marshalling
                          • No JPA / Hibernate style
                          • Query in Java as in Mongo Shell



mardi 4 décembre 12
db.users.find({ $or : [ { age : {$gt:20,$lt:30} } ,
                                            { age : {$gt:50,$lt:60} } ] })



                      Java Driver :
         DB db = mongo.getDB("users");

         DBCollection users = db.getCollection("users");

         DBObject firstQuery = QueryBuilder.start("age").greaterThan(20).lessThan(30).get();

         DBObject secondQuery = QueryBuilder.start("age").greaterThan(50).lessThan(60).get();

         DBObject query = QueryBuilder.start().or(firstQuery,secondQuery).get();

         DBCursor results = collection.find(query);

         List<User> users = new ArrayList<User>();	 	
         for (DBObject result : results) {

         	    User user = new User();
         	    user.setUsername((String) result.get("username"));
         	    user.setAge((Integer) result.get("age"));
              users.add(user);
         }

mardi 4 décembre 12
db.users.find({ $or : [ { age : {$gt:20,$lt:30} } ,
                                            { age : {$gt:50,$lt:60} } ] })



                      Jongo find


         MongoCollection collection = new Jongo(db).getCollection("users");

        Iterable<User> users = collection.find("{ $or : [ { age : {$gt:20,$lt:30} } , { age :
        {$gt:50,$lt:60} } ] }").as(User.class);




mardi 4 décembre 12
DB db = mongo.getDB("users");

                      DBCollection collection = db.getCollection("users");


                      DBObject firstQuery = QueryBuilder.start("age").greaterThan(20).lessThan(30).get();


                      DBObject secondQuery = QueryBuilder.start("age").greaterThan(50).lessThan(60).get();


                      DBObject query = QueryBuilder.start().or(firstQuery,secondQuery).get();


                      DBCursor results = collection.find(query);



                      List<User> users = new ArrayList<User>();	 	
                      for (DBObject result : results) {

                      	    User user = new User();
                      	    user.setUsername((String) result.get("username"));
                      	    user.setAge((Integer) result.get("age"));
                          users.add(user);
                      }




                      MongoCollection collection = new Jongo(db).getCollection("users");


                      Iterable<User> users = collection.find("{ $or : [ { age : {$gt:20,$lt:30} } , { age : {$gt:
                      50,$lt:60} } ] }").as(User.class);




mardi 4 décembre 12
db.users.update({ name : 'Joe' } ,
                                      { {$inc : {age : 1} },
                                      true, true)


                      Jongo update



               MongoCollection users = new Jongo(db).getCollection("users");



               users.update("{name: 'Joe'}").upsert().multi().with("{$inc: {age: 1}}");




mardi 4 décembre 12
Templating
          MongoCollection collection = new Jongo(db).getCollection("users");

          friends.find("{name: #, age: #}", "John", 18);

          {name: 'John', age: 18}




mardi 4 décembre 12
Aggregation Fw

          MongoCollection collection = new Jongo(db).getCollection("emails");

          collection.aggregate("{$project:{sender:1}}")
                    .and("{$match:{tags:'read'}}")
                    .and("{$limit:10}")
                    .as(Email.class);




mardi 4 décembre 12
Custom Mapper
          MongoCollection collection = new Jongo(db).getCollection("users");

          Iterable<Integer> ages = col.find("{'name':'John'}").map(
              new ResultMapper<Integer>() {
                  @Override
                  public Integer map(DBObject result) {
                       return result.get("age");
                  }
              }
          );




mardi 4 décembre 12
Conclusion
                      • Mongo Shell is pleasure, Java+Mongo can be
                        a pleasure too
                      • I would love Java Driver API was similar to
                        Jongo !




mardi 4 décembre 12
http://jongo.org/

                      https://github.com/bguerout/jongo


                      @bguerout - Benoit Guérout

                      @amsellemyves - Yves Amsellem

                      @karesti - Katia Aresti


mardi 4 décembre 12
Thank you for listening !!!




mardi 4 décembre 12

Más contenido relacionado

La actualidad más candente

Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDBScott Hernandez
 
Building a Social Network with MongoDB
  Building a Social Network with MongoDB  Building a Social Network with MongoDB
Building a Social Network with MongoDBFred Chu
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Javaantoinegirbal
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with GroovySten Anderson
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaScott Hernandez
 
LDAP and Active Directory Authentication in Plone
LDAP and Active Directory Authentication in PloneLDAP and Active Directory Authentication in Plone
LDAP and Active Directory Authentication in PloneClayton Parker
 
Back to Basics Webinar 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in DocumentsMongoDB
 
Javascript like objects and JSON processing in VBA
Javascript like objects and JSON processing in VBAJavascript like objects and JSON processing in VBA
Javascript like objects and JSON processing in VBABruce McPherson
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBYnon Perek
 
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제홍준 김
 
De normalised london aggregation framework overview
De normalised london  aggregation framework overview De normalised london  aggregation framework overview
De normalised london aggregation framework overview Chris Harris
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011Steven Francia
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMike Friedman
 
MongoDB for Perl Developers
MongoDB for Perl DevelopersMongoDB for Perl Developers
MongoDB for Perl DevelopersYnon Perek
 
Dev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesDev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesMongoDB
 

La actualidad más candente (19)

Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDB
 
Building a Social Network with MongoDB
  Building a Social Network with MongoDB  Building a Social Network with MongoDB
Building a Social Network with MongoDB
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Java
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with Groovy
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
LDAP and Active Directory Authentication in Plone
LDAP and Active Directory Authentication in PloneLDAP and Active Directory Authentication in Plone
LDAP and Active Directory Authentication in Plone
 
Back to Basics Webinar 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in Documents
 
Javascript like objects and JSON processing in VBA
Javascript like objects and JSON processing in VBAJavascript like objects and JSON processing in VBA
Javascript like objects and JSON processing in VBA
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
 
De normalised london aggregation framework overview
De normalised london  aggregation framework overview De normalised london  aggregation framework overview
De normalised london aggregation framework overview
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011
 
Active domain
Active domainActive domain
Active domain
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
MongoDB for Perl Developers
MongoDB for Perl DevelopersMongoDB for Perl Developers
MongoDB for Perl Developers
 
Dev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesDev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best Practices
 
Json
JsonJson
Json
 

Destacado

Building a scalable application- architecture considerations
Building a scalable application- architecture considerationsBuilding a scalable application- architecture considerations
Building a scalable application- architecture considerationsReliam
 
Why we built Kundera - The Polyglot Object Mapper for NoSQLs?
Why we built Kundera - The Polyglot Object Mapper for NoSQLs?Why we built Kundera - The Polyglot Object Mapper for NoSQLs?
Why we built Kundera - The Polyglot Object Mapper for NoSQLs?Vivek Shrivastava
 
JPoint'15 Mom, I so wish Hibernate for my NoSQL database...
JPoint'15 Mom, I so wish Hibernate for my NoSQL database...JPoint'15 Mom, I so wish Hibernate for my NoSQL database...
JPoint'15 Mom, I so wish Hibernate for my NoSQL database...Alexey Zinoviev
 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsJAX London
 
Mongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP DevelopersMongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP DevelopersRick Hightower
 
Shankar's mongo db presentation
Shankar's mongo db presentationShankar's mongo db presentation
Shankar's mongo db presentationShankar Kamble
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for BeginnersEnoch Joshua
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Tobias Trelle
 

Destacado (13)

Building a scalable application- architecture considerations
Building a scalable application- architecture considerationsBuilding a scalable application- architecture considerations
Building a scalable application- architecture considerations
 
Why we built Kundera - The Polyglot Object Mapper for NoSQLs?
Why we built Kundera - The Polyglot Object Mapper for NoSQLs?Why we built Kundera - The Polyglot Object Mapper for NoSQLs?
Why we built Kundera - The Polyglot Object Mapper for NoSQLs?
 
JBoss seam 2 part
JBoss seam 2 partJBoss seam 2 part
JBoss seam 2 part
 
JPoint'15 Mom, I so wish Hibernate for my NoSQL database...
JPoint'15 Mom, I so wish Hibernate for my NoSQL database...JPoint'15 Mom, I so wish Hibernate for my NoSQL database...
JPoint'15 Mom, I so wish Hibernate for my NoSQL database...
 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdams
 
Mongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP DevelopersMongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP Developers
 
Shankar's mongo db presentation
Shankar's mongo db presentationShankar's mongo db presentation
Shankar's mongo db presentation
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Mongo db
Mongo dbMongo db
Mongo db
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Mongo db
Mongo dbMongo db
Mongo db
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 

Similar a Jongo mongo sv

A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemLeonard Axelsson
 
Mongo db php_shaken_not_stirred_joomlafrappe
Mongo db php_shaken_not_stirred_joomlafrappeMongo db php_shaken_not_stirred_joomlafrappe
Mongo db php_shaken_not_stirred_joomlafrappeSpyros Passas
 
Groovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesGroovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesDarren Cruse
 
MongoDB-MFF.pptx
MongoDB-MFF.pptxMongoDB-MFF.pptx
MongoDB-MFF.pptxYellowGem
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaMongoDB
 
Java Core | Concurrency in the Java Language and Platform | Fredrik Ohrstrom
Java Core | Concurrency in the Java Language and Platform | Fredrik OhrstromJava Core | Concurrency in the Java Language and Platform | Fredrik Ohrstrom
Java Core | Concurrency in the Java Language and Platform | Fredrik OhrstromJAX London
 
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 FallJavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 FallYuichi Sakuraba
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB AppHenrik Ingo
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling rogerbodamer
 
MongoTalk/Voyage
MongoTalk/VoyageMongoTalk/Voyage
MongoTalk/VoyageESUG
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBMongoDB
 
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow BaselHow to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow BaselPatrick Baumgartner
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMetatagg Solutions
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDBNate Abele
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsSpringPeople
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDBFitz Agard
 

Similar a Jongo mongo sv (20)

A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy Ecosystem
 
Latinoware
LatinowareLatinoware
Latinoware
 
Mongo db php_shaken_not_stirred_joomlafrappe
Mongo db php_shaken_not_stirred_joomlafrappeMongo db php_shaken_not_stirred_joomlafrappe
Mongo db php_shaken_not_stirred_joomlafrappe
 
Groovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesGroovy Metaprogramming for Dummies
Groovy Metaprogramming for Dummies
 
MongoDB-MFF.pptx
MongoDB-MFF.pptxMongoDB-MFF.pptx
MongoDB-MFF.pptx
 
Full metal mongo
Full metal mongoFull metal mongo
Full metal mongo
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
 
Java Core | Concurrency in the Java Language and Platform | Fredrik Ohrstrom
Java Core | Concurrency in the Java Language and Platform | Fredrik OhrstromJava Core | Concurrency in the Java Language and Platform | Fredrik Ohrstrom
Java Core | Concurrency in the Java Language and Platform | Fredrik Ohrstrom
 
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 FallJavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 
MongoTalk/Voyage
MongoTalk/VoyageMongoTalk/Voyage
MongoTalk/Voyage
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
 
Dojo Confessions
Dojo ConfessionsDojo Confessions
Dojo Confessions
 
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow BaselHow to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
 

Más de Katia Aresti

Protocol Buffer Fantásticos y donde encontrarlos
Protocol Buffer Fantásticos y donde encontrarlosProtocol Buffer Fantásticos y donde encontrarlos
Protocol Buffer Fantásticos y donde encontrarlosKatia Aresti
 
Quand un lock a besoin d'être distribué
Quand un lock a besoin d'être distribuéQuand un lock a besoin d'être distribué
Quand un lock a besoin d'être distribuéKatia Aresti
 
How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...Katia Aresti
 
Trivial Java Second
Trivial Java SecondTrivial Java Second
Trivial Java SecondKatia Aresti
 
Trivial Java Second
Trivial Java SecondTrivial Java Second
Trivial Java SecondKatia Aresti
 
Trivial java First
Trivial java FirstTrivial java First
Trivial java FirstKatia Aresti
 
Mongo db et java en pratique
Mongo db et java en pratiqueMongo db et java en pratique
Mongo db et java en pratiqueKatia Aresti
 

Más de Katia Aresti (8)

Protocol Buffer Fantásticos y donde encontrarlos
Protocol Buffer Fantásticos y donde encontrarlosProtocol Buffer Fantásticos y donde encontrarlos
Protocol Buffer Fantásticos y donde encontrarlos
 
Quand un lock a besoin d'être distribué
Quand un lock a besoin d'être distribuéQuand un lock a besoin d'être distribué
Quand un lock a besoin d'être distribué
 
How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...
 
Mongo db devfestw
Mongo db devfestwMongo db devfestw
Mongo db devfestw
 
Trivial Java Second
Trivial Java SecondTrivial Java Second
Trivial Java Second
 
Trivial Java Second
Trivial Java SecondTrivial Java Second
Trivial Java Second
 
Trivial java First
Trivial java FirstTrivial java First
Trivial java First
 
Mongo db et java en pratique
Mongo db et java en pratiqueMongo db et java en pratique
Mongo db et java en pratique
 

Jongo mongo sv

  • 1. Mongo + Java = Jongo Mongo and Java made easy ! by @karesti - MongoSV 2012 mardi 4 décembre 12
  • 2. Agile Developer MongoDB User @karesti MongoDB Master Katia Aresti mardi 4 décembre 12
  • 3. Back on 2010 ... mardi 4 décembre 12
  • 4. {mongo : "awesome"} mardi 4 décembre 12
  • 5. DBObject API REST Web Services Search of POI-s {DBObject : "not bad, not awesome"} mardi 4 décembre 12
  • 6. Back on 2010 ... Morphia ? mardi 4 décembre 12
  • 7. Morphia JPA-LIKE mardi 4 décembre 12
  • 8. So ... • Morphia is great, good work ! • But : Need to learn another API => Mongo, Java Driver, Morphia • But : JPA Like -> Mongo Paradigm is not JPA / Hibernate • Morphia is comming to Java Driver ? • Final choice : • Morphia for the Java - DBObject Mapping mardi 4 décembre 12
  • 9. Late 2011 ... mardi 4 décembre 12
  • 10. @bguerout Jongo @amsellemyves • What’s Jongo ? • ODM on top of the Java Driver • Jackson and BSON4Jackson for (Un)marshalling • No JPA / Hibernate style • Query in Java as in Mongo Shell mardi 4 décembre 12
  • 11. db.users.find({ $or : [ { age : {$gt:20,$lt:30} } , { age : {$gt:50,$lt:60} } ] }) Java Driver : DB db = mongo.getDB("users"); DBCollection users = db.getCollection("users"); DBObject firstQuery = QueryBuilder.start("age").greaterThan(20).lessThan(30).get(); DBObject secondQuery = QueryBuilder.start("age").greaterThan(50).lessThan(60).get(); DBObject query = QueryBuilder.start().or(firstQuery,secondQuery).get(); DBCursor results = collection.find(query); List<User> users = new ArrayList<User>(); for (DBObject result : results) { User user = new User(); user.setUsername((String) result.get("username")); user.setAge((Integer) result.get("age")); users.add(user); } mardi 4 décembre 12
  • 12. db.users.find({ $or : [ { age : {$gt:20,$lt:30} } , { age : {$gt:50,$lt:60} } ] }) Jongo find MongoCollection collection = new Jongo(db).getCollection("users"); Iterable<User> users = collection.find("{ $or : [ { age : {$gt:20,$lt:30} } , { age : {$gt:50,$lt:60} } ] }").as(User.class); mardi 4 décembre 12
  • 13. DB db = mongo.getDB("users"); DBCollection collection = db.getCollection("users"); DBObject firstQuery = QueryBuilder.start("age").greaterThan(20).lessThan(30).get(); DBObject secondQuery = QueryBuilder.start("age").greaterThan(50).lessThan(60).get(); DBObject query = QueryBuilder.start().or(firstQuery,secondQuery).get(); DBCursor results = collection.find(query); List<User> users = new ArrayList<User>(); for (DBObject result : results) { User user = new User(); user.setUsername((String) result.get("username")); user.setAge((Integer) result.get("age")); users.add(user); } MongoCollection collection = new Jongo(db).getCollection("users"); Iterable<User> users = collection.find("{ $or : [ { age : {$gt:20,$lt:30} } , { age : {$gt: 50,$lt:60} } ] }").as(User.class); mardi 4 décembre 12
  • 14. db.users.update({ name : 'Joe' } , { {$inc : {age : 1} }, true, true) Jongo update MongoCollection users = new Jongo(db).getCollection("users"); users.update("{name: 'Joe'}").upsert().multi().with("{$inc: {age: 1}}"); mardi 4 décembre 12
  • 15. Templating MongoCollection collection = new Jongo(db).getCollection("users"); friends.find("{name: #, age: #}", "John", 18); {name: 'John', age: 18} mardi 4 décembre 12
  • 16. Aggregation Fw MongoCollection collection = new Jongo(db).getCollection("emails"); collection.aggregate("{$project:{sender:1}}") .and("{$match:{tags:'read'}}") .and("{$limit:10}") .as(Email.class); mardi 4 décembre 12
  • 17. Custom Mapper MongoCollection collection = new Jongo(db).getCollection("users"); Iterable<Integer> ages = col.find("{'name':'John'}").map( new ResultMapper<Integer>() { @Override public Integer map(DBObject result) { return result.get("age"); } } ); mardi 4 décembre 12
  • 18. Conclusion • Mongo Shell is pleasure, Java+Mongo can be a pleasure too • I would love Java Driver API was similar to Jongo ! mardi 4 décembre 12
  • 19. http://jongo.org/ https://github.com/bguerout/jongo @bguerout - Benoit Guérout @amsellemyves - Yves Amsellem @karesti - Katia Aresti mardi 4 décembre 12
  • 20. Thank you for listening !!! mardi 4 décembre 12