Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MongoDB + Spring

855 views

Published on

The integration between Spring Framework and MongoDB tends to be somewhat unknown. This presentation shows the different projects that compose Spring ecosystem, Springdata, Springboot, SpringIO etc and how to merge between the pure JAVA projects to massive enterprise systems that require the interaction of these systems together.

  • Be the first to comment

MongoDB + Spring

  1. 1. MongoDB + Spring Norberto Leite @nleite norberto@mongodb.com http://www.mongodb.com/norberto Two leafs of the same tree
  2. 2. 3 Agenda • MongoDB Introduction – Just in case you've been distracted • Spring Framework Overview • Spring + MongoDB – Spring Data – Spring Boot – Spring Batch
  3. 3. 4 Ola, I'm Norberto! Norberto Leite Technical Evangelist Madrid, Spain @nleite norberto@mongodb.com http://www.mongodb.com/norberto
  4. 4. MongoDB
  5. 5. 6 MongoDB GENERAL PURPOSE DOCUMENT DATABASE OPEN-SOURCE
  6. 6. 7 MONGODB FEATURES JSON Document Model with Dynamic Schemas Auto-Sharding for Horizontal Scalability Text Search Aggregation Framework and MapReduce Full, Flexible Index Support and Rich Queries Built-In Replication for High Availability Advanced Security Large Media Storage with GridFS
  7. 7. 8 THE LARGEST ECOSYSTEM 9,000,000+ MongoDB Downloads 250,000+ Online Education Registrants 35,000+ MongoDB User Group Members 35,000+ MongoDB Management Service (MMS) Users 750+ Technology and Services Partners 2,000+ Customers Across All Industries
  8. 8. Document Data Model Relational MongoDB { first_name: ‘Paul’, surname: ‘Miller’, city: ‘London’, location: [45.123,47.232], cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } ] }
  9. 9. 10 Documents are Rich Data Structures { first_name: ‘Paul’, surname: ‘Miller’, cell: ‘+447557505611’ city: ‘London’, location: [45.123,47.232], Profession: [banking, finance, trader], cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } ] } Fields can contain an array of sub- documents Fields Typed field values Fields can contain arrays
  10. 10. 11 Document Model Benefits Agility and flexibility Data model supports business change Rapidly iterate to meet new requirements Intuitive, natural data representation Eliminates ORM layer Developers are more productive Reduces the need for joins, disk seeks Programming is more simple Performance delivered at scale { _id : ObjectId("4c4ba5e5e8aabf3"), employee_name: "Dunham, Justin", department : "Marketing", title : "Product Manager, Web", report_up: "Neray, Graham", pay_band: “C", benefits : [ { type : "Health", plan : "PPO Plus" }, { type : "Dental", plan : "Standard" } ] }
  11. 11. Dynamic Schema { policyNum: 123, type: auto, customerId: abc, payment: 899, deductible: 500, make: Taurus, model: Ford, VIN: 123ABC456, } { policyNum: 456, type: life, customerId: efg, payment: 240, policyValue: 125000, start: jan, 1995 end: jan, 2015 } { policyNum: 789, type: home, customerId: hij, payment: 650, deductible: 1000, floodCoverage: No, street: “10 Maple Lane”, city: “Springfield”, state: “Maryland” }
  12. 12. Query Operators Conditional Operators $all, $exists, $mod, $ne, $in, $nin, $nor, $or, $size, $type $lt, $lte, $gt, $gte // find customers with any claims > db.customers.find( {claims: {$exists: true }} ) // find customers matching a regular expression > db.customers.find( {last: /^rog*/i } ) // count customers by city > db.customers.find( {city: ‘Philadelphia’} ).count()
  13. 13. 14 Indexes // Index nested documents > db.customers.ensureIndex({“policies.agent”:1} ) > db.customers.find({‘policies.agent’:’Fred’}) // geospatial index > db.customers.ensureIndex({“property.location”: “2d” } ) > db.customers.find({“property.location” : { $near : [22,42] }} ) // text index > db.customers.ensureIndex({“policies.notes”: “text” } )
  14. 14. MongoDB is Fully Featured
  15. 15. Spring Framework Not just a framework!
  16. 16. 17 Spring Framework
  17. 17. Spring Projects
  18. 18. Spring & MongoDB
  19. 19. Same Tree?
  20. 20. Let's put these 2 to work!
  21. 21. Build a "cool" App
  22. 22. 24 Nice and simple
  23. 23. 25 Video Catalog App • All videos from our Education platform – Yes, we have the coolest framework ever for remote education! https://university.mongodb.com/
  24. 24. 26 Video Catalog App • All videos from our Education platform – Yes, we have the coolest framework ever for remote education! • Load information into MongoDB • Allow people to vote on videos • Find videos based on the metadata • All using Spring Projects – Let's also look into optimizations
  25. 25. 27 Stack MongoDB DAL – Database Access Layer demo.springio.batch REST API
  26. 26. CODE, CODE, CODE
  27. 27. 29 DAL • Decoupling Database – Rule n1 on good Software Development • Base Library • Simple
  28. 28. 30 Batch • Batch Configuration Class – reader() – writer() @Configuration @EnableBatchProcessing • ItemProcessor() – Excellent way to do pre-aggregations, computations…
  29. 29. 31 Batch • Things to look for – chunk(chunkSize) • Keep an eye on this value to optmise the loading process – writer() • MongoDB bulk insert is here to help
  30. 30. 32 REST API @RestController @RequestMapping("/…") @EnableAutoConfiguration … extends MongoRepository<T, I>
  31. 31. 33 REST API • Things to have in mind – MongoRepository is "just" CRUD repository • Need to autowire MongoTemplate to aggregate – Updates • Not a particular issue of SpringData • General thing of ODM's
  32. 32. http://1.bp.blogspot.com/-H40bE-rJUqk/UXo3YatYjqI/AAAAAAAAAho/zjrQVk3WrNA/s1600/paella_03.jpg Take Ways
  33. 33. 35 Recap • Spring has a lot of things out of the box that we do not need to reinvent the all the time • MongoDB can easily be integrated with existing Spring based projects • Performance is important • Continuous Improvement is key!
  34. 34. 36 Recap • DOCUMENTATION! – Awesome and complete on both projects!
  35. 35. We love enterprise!
  36. 36. 38 MongoDB 3.0 is here!
  37. 37. http://www.humanandnatural.com/data/media/178/badan_jaran_desert_oasis_china.jpg http://www.tinypm.com/blog/wp-content/uploads/2015/01/hammer.jpg Fully Available! 3.0.2 https://www.mongodb.org/downloads http://www.mongodb.com/norberto
  38. 38. 40 Register now: mongodbworld.com Early Bird Ends May 1! Use Code NorbertoLeite for additional 25% Off *Come as a group of 3 or more – Save another 25%
  39. 39. We’re Always Looking for Top Talent What are employees saying? “Working with a group of individuals who you know will have your back is one of the reasons I love working at MongoDB” “Every day, we get to solve hard problems that make distributed databases more accessible to developers all over the world” “MongoDB lets you tackle real problems that affect hundreds of thousands of users” Visit us at www.mongodb.com/careers to see a full list of opportunities or email your resume to norberto@mongodb.com What are we hiring for? • Technical Services Engineers (Dublin) • Consulting Engineers (UK OR France) • Solution Architects (France, Spain, Germany) • Enterprise Account Executives ( France, Italy, UK, Germany) • Corporate Account Executives (Dublin) • Renewals Account Managers (Dublin)
  40. 40. Same Tree!!!
  41. 41. http://www.humanandnatural.com/data/media/178/badan_jaran_desert_oasis_china.jpg Questions? @nleite norberto@mongodb.com

×