MongoDB + Java + Spring Data

11,833
-1

Published on

Published in: Technology, News & Politics
0 Comments
20 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
11,833
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
20
Embeds 0
No embeds

No notes for slide

MongoDB + Java + Spring Data

  1. 1. MongoDB + JAVA + Spring dataAnton SulzhenkoJava Software EngineerAnton_Sulzhenko@epam.com
  2. 2. MongoDB + Java + Spring Data MongoDB Java Spring Data
  3. 3. 3 MongoDB Java Spring DataWhat is NoSQL?• Non-relational data• Schemaless• No JOINs, No complex transactions• Horizontal scalability
  4. 4. 4 MongoDB Java Spring Data• Key-value(Redis, MemcaheDB)• Wide column(BigTable, Cassandra, HBase)• Document(MongoDB, CouchDB, Riak)• Graph(Neo4j, FlockDB)
  5. 5. 5MongoDB Java Spring Data
  6. 6. MongoDBDocumented-oriented database
  7. 7. 7 MongoDB Java Spring Data MongoDB TerminologyRDBMS Mongo DBDatabase DatabaseTable CollectionRow JSON documentColumn FieldIndex IndexJoin Embedded documents & linkingAggregation (e.g. group by) Aggregation framework
  8. 8. 8 MongoDB Java Spring DataMongoDB Features• JSON data model with dynamic schemas• CRUD operations• Atomic document operations• Ad hoq Queries like SQL (equality, regexp, ranges, geospatial)• Full, flexible index support• Auto-sharding for horizontal scalability• Built-in replication and high availability
  9. 9. 9 MongoDB Java Spring DataMongoDB Drivers• One wire protocol for all client languages• A driver implementation per language• Responsibilities: - Converting language dependent data structures <-> BSON - Generating ObjectId for _id field
  10. 10. 10MongoDB + Java + Spring Data MongoDB Java Spring Data
  11. 11. 11 MongoDB Java Spring DataMongoDB Java Driver Features• CRUD• Support for replica sets• Connection pooling• Distributed reads to slave servers• BSON serializerdesirializer• JSON serializerdesirializer• GridFS
  12. 12. 12 MongoDB Java Spring DataMongoDB Java Driver Usage
  13. 13. 13MongoDB + Java + Spring Data MongoDB Java Spring Data
  14. 14. SPRING DATAMongoDB
  15. 15. 15 MongoDB Java Spring DataSpring Data MongoDB• Templating • Resource abstraction • Configure connections to mongod/mongos node(s) • Collection lifecycle (create/drop) • Map/Reduce / Aggregation• Object mapping • Annotation based: @Document, @Field, @Index etc. • Classes are mapped to collections, Java Objects to documents• Repository Support • Queries are derived from method signatures • Geospatial Queries
  16. 16. 16 MongoDB Java Spring DataInstantiating MongoTemplate using XML based metadata:
  17. 17. 17 MongoDB Java Spring DataSample CRUD operations using MongoTemplate:
  18. 18. 18 MongoDB Java Spring Data Mapping annotation overview:• @Id• @Document• @DBRef• @Indexed• @CompoundIndex• @GeoSpatialIndexed• @Transient• @PersistenceConstructor• @Value
  19. 19. 19MongoDB Java Spring Data
  20. 20. 20 MongoDB Java Spring DataSpring Data MongoDB: Repositories• Main concept: • Use the signature of a method to derive the query(at runtime)• Base implementations / abstractions for • CRUD operations • Paging • Sorting
  21. 21. 21 MongoDB Java Spring DataSpring Data MongoDB: Repositories
  22. 22. 22 MongoDB Java Spring Data Spring Data MongoDB: Repositories Supported keywords for query methods: Keyword Logical resultGreaterThan {"age" : {"$gt" : age}}LessThan {"age" : {"$lt" : age}}Between {"age" : {"$gt" : from, "$lt" : to}}IsNotNull, NotNull {"age" : {"$ne" : null}}IsNull, Null {"age" : null}Like {"age" : age} ( age as regex)(No keyword) {"age" : name}Not {"age" : {"$ne" : name}}Near {"location" : {"$near" : [x,y]}}Within {"location" : {"$within" : {"$center" : [ [x, y], distance]}}}Within {"location" : {"$within" : {"$box" : [ [x1, y1], x2, y2]}}}
  23. 23. 23 MongoDB Java Spring DataSpring Data MongoDB: Repositories
  24. 24. 24 MongoDB Java Spring Data• Map/Reduce / Aggregation framework• Index management• Support for GridFS• Geospatial indexes/queries• Optimistic Locking
  25. 25. 25 MongoDB Java Spring Data• 10gen Education • https://education.10gen.com/• Spring Data - MongoDB • http://www.springsource.org/spring-data/mongodb• The Little MongoDB Book • http://openmymind.net/2011/3/28/The-Little-MongoDB-Book/
  26. 26. 26 Questions? MongoDB Java Spring DataAnton Sulzhenko Anton_Sulzhenko@epam.com

×