The Spring Data MongoDB Project

2,565 views
2,419 views

Published on

This talk will introduce the Spring Data MongoDB project. Spring Data MongoDB provides a feature rich library for writing MongoDB applications in Java. It builds upon the Spring Framework and as such promotes a POJO programming model with a strong emphasis on productivity.
The Spring MongoDB Project provides a rich object mapper, a MongoTemplate helper class to simplify common document access operations using query, criteria, and update DSLs, automatic repository interface implementations, QueryDSL integration, and cross-store persistence.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,565
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
61
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • The Spring Data MongoDB Project

    1. 1. MongoDB and Spring Data Chris Harris Twitter : cj_harris5 Email : charris@10gen.com© 2012 SpringOne 2GX. All rights reserved. Do not distribute without permission.
    2. 2. About Me Solution Architect at 10gen (the company behind MongoDB)- Previous Roles: • EMEA Architect at SpringSource • EMEA Principal JBoss Consultant at RedHat22
    3. 3. http://images.mirror.co.uk/upl/m4/mar2009/0/2/satnav-cliff-hanger-pic-ross-parry- image-3-213726463.jpg
    4. 4. http://www.simpleadhdexpert.com/wp-content/uploads/2009/08/frustration.jpg
    5. 5. http://daddytypes.com/archive/duct_tape_baby_mianro.jpg
    6. 6. Is there a better way?
    7. 7. TerminologyRDBMS MongoDBTable CollectionRow(s) JSON DocumentIndex IndexJoin Embedding & LinkingPartition ShardPartition Key Shard Key
    8. 8. As simple as possible, but no simpler Memcached Key / ValueScalability & Performance MongoDB RDBMS Depth of functionality
    9. 9. Lets build a Spring Data MongoDB App!
    10. 10. Welcome to Dev News• User Story 1: – As a user I should be able to create “News Articles”
    11. 11. What is a News Article?{ title: “What is new in 2.2 MongoDB”, date : new Date(), author : “Fred” text : “.......”}
    12. 12. Example 1 - Create
    13. 13. Welcome to MongoDB News Dev• User Story 1: – As a user I should be able to create “News Articles”• User Story 2: – As a user I should be able to find a “News Articles” by Name
    14. 14. Example 2 - Query
    15. 15. Example 3 - Repo
    16. 16. Welcome to MongoDB News Dev• User Story 1: – As a user I should be able to create “News Articles”• User Story 2: – As a user I should be able to find a “News Articles” by Name• User Story 3: – As a user I should be able to comment on “News Articles”
    17. 17. What is a Comment?{ title: “What is new in 2.2 MongoDB”, date : new Date(), author : “Fred” text : “.......” tags : [“mongodb”, “nosql”] comments : [ {author : “chris”, text: “this is great” , date : new Date()}, {author : “tom”, text: “rock on”, date : new Date()} ]}
    18. 18. Example 4 - Comments
    19. 19. Welcome to MongoDB News Dev• User Story 1: – As a user I should be able to create “News Articles”• User Story 2: – As a user I should be able to find a “News Articles” by Name• User Story 3: – As a user I should be able to comment on “News Articles”• User Story 4: –As a user I want to know how many comments are on a “Articles”
    20. 20. What is a Comment?{ title: “What is new in 2.2 MongoDB”, .... comments : [ {author : “chris”, text: “this is great” , date : new Date()}, {author : “tom”, text: “rock on”, date : new Date()} ], comments: count : 2}
    21. 21. Example 5 - Inc
    22. 22. “MongoDB lost my data!!”
    23. 23. Data: 125647383885969795743
    24. 24. Least durability - Dont use! Driver MongoDB write apply in memory
    25. 25. Wait for Journal Sync - Same as RDBMS Driver MongoDB write apply in memory j:true Write to journal
    26. 26. Replication http://www.flickr.com/photos/10335017@N07/4570943043
    27. 27. Replica Set• Data Protection• Multiple copies of the data• Spread across Data Centers, AZs• High Availability• Automated Failover• Automated Recovery
    28. 28. Replica Sets Write Primary Asynchronous Replication Read Java App Secondary Secondary
    29. 29. Replica Sets Write Primary Read Java App Secondary Secondary
    30. 30. Replica Sets Primary Write Automatic Election of new Java App Primary Primary Read Secondary
    31. 31. Replica Sets Recovering Write New primary serves data Java App Primary Read Secondary
    32. 32. Replica Sets Secondary Write Java App Primary Read Secondary
    33. 33. Durability Summary Other Data Memory Journal Secondary Center RDBMS Default"Fire & Forget" w=1 w=1 j=truew="majority" w=nw="myTag" Less More
    34. 34. Example 6 - Write Concern
    35. 35. Eventual Consistency• http://www.flickr.com/photos/26095468@N04/3779692985
    36. 36. Understanding Eventual Consistency Thread #1 Primary Secondary Insert v1
    37. 37. Understanding Eventual Consistency Thread #1 Primary Secondary Insert v1 v1
    38. 38. Understanding Eventual Consistency Thread #1 Primary Secondary Insert v1 Read v1
    39. 39. Understanding Eventual Consistency Thread #1 Primary Secondary Insert v1reads v1 Read v1
    40. 40. Understanding Eventual Consistency Thread #1 Primary Secondary Insert v1reads v1 Read v1 Update v2
    41. 41. Understanding Eventual Consistency Thread #1 Primary Secondary Insert v1reads v1 Read v1 Update v2 v2
    42. 42. Understanding Eventual Consistency Thread #1 Primary Secondary Insert v1reads v1 Read v1 Update v2 Read v2
    43. 43. Understanding Eventual Consistency Thread #1 Primary Secondary Insert v1reads v1 Read v1 Update v2reads v2 Read v2
    44. 44. Understanding Eventual Consistency Thread #1 Primary Secondary Thread #2 Insert v1 Read v1 Update v2 Read v2
    45. 45. Understanding Eventual Consistency Thread #1 Primary Secondary Thread #2 Insert v1 Read v1 Update v2 Read v2
    46. 46. Understanding Eventual Consistency Thread #1 Primary Secondary Thread #2 Insert v1 v1 does not exist on Read Secondary v1 Update v2 Read v2
    47. 47. Understanding Eventual Consistency Thread #1 Primary Secondary Thread #2 Insert v1 v1 does not exist on Read Secondary v1 Update v2 Reads v1 but Primary at v2 Read v2 Read v2
    48. 48. Example 7 - Eventual Consistency
    49. 49. http://community.qlikview.com/cfs-filesystemfile.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theqlikviewblog/Cutting-Grass-with-Scissors-_2D00_-2.jpg
    50. 50. http://www.bitquill.net/blog/wp-content/uploads/2008/07/pack_of_harvesters.jpg
    51. 51. MongoDB Sharding• Automatic partitioning and management• Range based• Convert to sharded system with no downtime• Fully consistent
    52. 52. How mongoDB Sharding works> db.runCommand({addshard: "shard1"});> db.runCommand({shardCollection: "mydb.users", key: {age: 1}}) -∞   +∞  • Range keys from -∞ to +∞• Ranges are stored as "chunks"
    53. 53. How mongoDB Sharding works> db.users.save({age: 40}) -∞   +∞   -∞   40 41 +∞  • Data in inserted• Ranges are split into more "chunks"
    54. 54. How mongoDB Sharding works> db.users.save({age: 40})> db.users.save({age: 50})> db.users.save({age: 60}) -∞   +∞   -∞   40 41 +∞   41 50 51 +∞   51 60 61 +∞  
    55. 55. How mongoDB Sharding works> db.runCommand({addshard: "shard2"});> db.runCommand({addshard: "shard3"}); -∞   40 41 50 51 60 61 +∞  
    56. 56. How mongoDB Sharding works> db.runCommand({addshard: "shard2"});> db.runCommand({addshard: "shard3"}); shard1 -∞   40 41 50 51 60 61 +∞  
    57. 57. How mongoDB Sharding works> db.runCommand({addshard: "shard2"});> db.runCommand({addshard: "shard3"}); shard1 shard2 shard3 -∞   40 41 50 51 60 61 +∞  
    58. 58. Architecture app app Config Servers mongos mongos C1 C2 C3 Replica Set mongod mongod mongod mongod mongod mongod mongod mongod mongod mongod mongod mongod Shard 1 Shard 2 Shard 3 Shard 4
    59. 59. Balancing mongos config mongos balancer config config Data inserted Imbalance all in a range 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Shard 1 Shard 2 Shard 3 Shard 4
    60. 60. Balancing mongos config mongos balancer config config Move chunk 1 to Shard 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Shard 1 Shard 2 Shard 3 Shard 4
    61. 61. Balancing mongos config balancer config config 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Shard 1 Shard 2 Shard 3 Shard 4
    62. 62. Balancing mongos config balancer config config 2 3 4 5 6 7 8 1 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Shard 1 Shard 2 Shard 3 Shard 4
    63. 63. Balancing mongos config mongos balancer config config 2 3 4 5 6 7 8 1 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Shard 1 Shard 2 Shard 3 Shard 4
    64. 64. Example 8 - Sharding
    65. 65. Questions• MongoDB 2.2 – Improved concurrency – Tag-aware sharding – Aggregation framework – TTL collections• Free online MongoDB training – Develop – Deploy – Classes start Oct. 2012

    ×