Jongo mongo sv

3,765 views

Published on

Jongo Quick presentation

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,765
On SlideShare
0
From Embeds
0
Number of Embeds
771
Actions
Shares
0
Downloads
24
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Jongo mongo sv

  1. 1. Mongo + Java = Jongo Mongo and Java made easy ! by @karesti - MongoSV 2012mardi 4 décembre 12
  2. 2. Agile Developer MongoDB User @karesti MongoDB Master Katia Arestimardi 4 décembre 12
  3. 3. Back on 2010 ...mardi 4 décembre 12
  4. 4. {mongo : "awesome"}mardi 4 décembre 12
  5. 5. DBObject API REST Web Services Search of POI-s {DBObject : "not bad, not awesome"}mardi 4 décembre 12
  6. 6. Back on 2010 ... Morphia ?mardi 4 décembre 12
  7. 7. Morphia JPA-LIKEmardi 4 décembre 12
  8. 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 Mappingmardi 4 décembre 12
  9. 9. Late 2011 ...mardi 4 décembre 12
  10. 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 Shellmardi 4 décembre 12
  11. 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. 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. 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. 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. 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. 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. 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. 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. 19. http://jongo.org/ https://github.com/bguerout/jongo @bguerout - Benoit Guérout @amsellemyves - Yves Amsellem @karesti - Katia Arestimardi 4 décembre 12
  20. 20. Thank you for listening !!!mardi 4 décembre 12

×