mongo db with spring data document
DESCRIPTION
TRANSCRIPT
MongoDB withSpring Data Document
Sean@WeaveusMay 2011
MongoDBDriver
MongoTemplate
MongoOperations
<<interface>>
Bean
Bean
@Autowired
2Monday, May 9, 2011
DB
Collection#1 Collection#2
Document#1
Document#2
Document#3
Document#4
Document#5
Document#1
Document#2
Document#3
Document#4
Document#5
Document := {UniqueID, JSON Document}
3Monday, May 9, 2011
Getting Started - Server
SeaniMac:tmp sean$ lsmongodb-osx-x86_64-1.8.1.tgzmongodb-osx-x86_64-1.8.1SeaniMac:tmp sean$ mkdir -p mongodb-data/dbSeaniMac:tmp sean$ ./mongodb-osx-x86_64-1.8.1/bin/mongod --dbpath ./mongodb-data/dbFri May! 6 14:16:48 [initandlisten] MongoDB starting ......
4Monday, May 9, 2011
Getting Started - Client
SeaniMac:tmp sean$ ./mongodb-osx-x86_64-1.8.1/bin/mongoMongoDB shell version: 1.8.1connecting to: test> db.foo.save( { a: 1 } )> db.foo.find(){ "_id" : ObjectId("4dc3855d3044bae59620330d"), "a" : 1 }
5Monday, May 9, 2011
Java(Groovy)import com.mongodb.Mongoimport com.mongodb.DBimport com.mongodb.DBCollection
Mongo m = new Mongo()println m.databaseNames
DB db = m.getDB("test")println db.collectionNames
DBCollection dbcol = db.getCollection("foo")println dbcol.find().next() // DBObject Instance, BSON
// results[test, admin, db, foo, local][foo, system.indexes][_id:4dc3855d3044bae59620330d, a:1.0]
6Monday, May 9, 2011
Document CRUD
7Monday, May 9, 2011
Save
> db.things.save({ name: "mongo" })> t = { x : 3 }{ "x" : 3 }> db.things.save(t)
8Monday, May 9, 2011
Find> db.things.find(){ "_id" : ObjectId("4dc399fc3044bae59620330e"), "name" : "mongo" }{ "_id" : ObjectId("4dc3a7913044bae59620330f"), "x" : 3 }> var cursor = db.things.find();> while (cursor.hasNext()) printjson(cursor.next());{ "_id" : ObjectId("4dc399fc3044bae59620330e"), "name" : "mongo" }{ "_id" : ObjectId("4dc3a7913044bae59620330f"), "x" : 3 }> db.things.find().forEach( printjson ){ "_id" : ObjectId("4dc399fc3044bae59620330e"), "name" : "mongo" }{ "_id" : ObjectId("4dc3a7913044bae59620330f"), "x" : 3 }
> db.things.find({name:"mongo"}).forEach( printjson );{ "_id" : ObjectId("4dc399fc3044bae59620330e"), "name" : "mongo" }
> db.things.save( {"name":"nosql", "title":"nonRDB"} )> db.things.find( {name:"nosql"}, {title:true} ).forEach( printjson ){ "_id" : ObjectId("4dc3ae133044bae596203312"), "title" : "nonRDB" }
9Monday, May 9, 2011
Remove
> db.things.remove({name:"mongo"})> db.things.remove({"_id":ObjectId("4dc3ae133044bae596203312")})> db.things.find()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{ "_id" : ObjectId("4dc3a7913044bae59620330f"), "x" : 3 }
10Monday, May 9, 2011
with Spring Data
11Monday, May 9, 2011
MongoTemplate
• Document databases extension to Spring Programming Model
• SPEL
• DataException hierarchy
• IoC Configuration
12Monday, May 9, 2011
Beans @Configuration or XML-Based
13Monday, May 9, 2011
MongoDBDriver
MongoTemplate
MongoOperations
<<interface>>
Bean
Bean
@AutowiredMongo
Repository
MongoCriteria
14Monday, May 9, 2011
Object-DocumentImplicit Conversion
15Monday, May 9, 2011
• MongoRepository
• Method name based Query
• @Query, QueryDSL
• Criteria, Predication Support
• GPS Query
• Mapping
• @Document(Instead of @Entity)
• Asynchronous Callback
16Monday, May 9, 2011