MongoDB with               Spring Data Document                      Sean@Weaveus                         May 2011Monday, ...
<<interface>>                      @Autowired                                    Mongo                                   O...
DB                      Collection#1        Collection#2                        Document#1          Document#1            ...
Getting Started - Server   SeaniMac:tmp sean$ ls   mongodb-osx-x86_64-1.8.1.tgz   mongodb-osx-x86_64-1.8.1   SeaniMac:tmp ...
Getting Started - Client   SeaniMac:tmp sean$ ./mongodb-osx-x86_64-1.8.1/bin/mongo   MongoDB shell version: 1.8.1   connec...
Java(Groovy)   import com.mongodb.Mongo   import com.mongodb.DB   import com.mongodb.DBCollection   Mongo m = new Mongo() ...
Document CRUDMonday, May 9, 2011                   7
Save   >   db.things.save({ name: "mongo" })   >   t = { x : 3 }   {   "x" : 3 }   >   db.things.save(t)Monday, May 9, 201...
Find   >   db.things.find()   {   "_id" : ObjectId("4dc399fc3044bae59620330e"), "name" : "mongo" }   {   "_id" : ObjectId(...
Remove   >   db.things.remove({name:"mongo"})   >   db.things.remove({"_id":ObjectId("4dc3ae133044bae596203312")})   >   d...
with Spring DataMonday, May 9, 2011                      11
MongoTemplate                •     Document databases extension to Spring                      Programming Model          ...
Beans @Configuration or XML-BasedMonday, May 9, 2011                                      13
<<interface>>                                                     Mongo                                    Mongo          ...
Object-Document                      Implicit ConversionMonday, May 9, 2011                         15
•     MongoRepository                      •   Method name based Query                      •   @Query, QueryDSL          ...
Upcoming SlideShare
Loading in...5
×

Mongo db with spring data document

3,966

Published on

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,966
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
49
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Mongo db with spring data document"

  1. 1. MongoDB with Spring Data Document Sean@Weaveus May 2011Monday, May 9, 2011 1
  2. 2. <<interface>> @Autowired Mongo Operations Bean Mongo Template Bean MongoDB DriverMonday, May 9, 2011 2
  3. 3. DB Collection#1 Collection#2 Document#1 Document#1 Document#2 Document#2 Document#3 Document#3 Document#4 Document#4 Document#5 Document#5 Document := {UniqueID, JSON Document}Monday, May 9, 2011 3
  4. 4. Getting Started - Server SeaniMac:tmp sean$ ls mongodb-osx-x86_64-1.8.1.tgz mongodb-osx-x86_64-1.8.1 SeaniMac:tmp sean$ mkdir -p mongodb-data/db SeaniMac:tmp sean$ ./mongodb-osx-x86_64-1.8.1/bin/mongod --dbpath ./ mongodb-data/db Fri May  6 14:16:48 [initandlisten] MongoDB starting ... ...Monday, May 9, 2011 4
  5. 5. Getting Started - Client SeaniMac:tmp sean$ ./mongodb-osx-x86_64-1.8.1/bin/mongo MongoDB shell version: 1.8.1 connecting to: test > db.foo.save( { a: 1 } ) > db.foo.find() { "_id" : ObjectId("4dc3855d3044bae59620330d"), "a" : 1 }Monday, May 9, 2011 5
  6. 6. Java(Groovy) import com.mongodb.Mongo import com.mongodb.DB import 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]Monday, May 9, 2011 6
  7. 7. Document CRUDMonday, May 9, 2011 7
  8. 8. Save > db.things.save({ name: "mongo" }) > t = { x : 3 } { "x" : 3 } > db.things.save(t)Monday, May 9, 2011 8
  9. 9. 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" }Monday, May 9, 2011 9
  10. 10. Remove > db.things.remove({name:"mongo"}) > db.things.remove({"_id":ObjectId("4dc3ae133044bae596203312")}) > db.things.find()                                              { "_id" : ObjectId("4dc3a7913044bae59620330f"), "x" : 3 }Monday, May 9, 2011 10
  11. 11. with Spring DataMonday, May 9, 2011 11
  12. 12. MongoTemplate • Document databases extension to Spring Programming Model • SPEL • DataException hierarchy • IoC ConfigurationMonday, May 9, 2011 12
  13. 13. Beans @Configuration or XML-BasedMonday, May 9, 2011 13
  14. 14. <<interface>> Mongo Mongo @Autowired Repository Operations Mongo Criteria Bean Mongo Template Bean MongoDB DriverMonday, May 9, 2011 14
  15. 15. Object-Document Implicit ConversionMonday, May 9, 2011 15
  16. 16. • MongoRepository • Method name based Query • @Query, QueryDSL • Criteria, Predication Support • GPS Query • Mapping • @Document(Instead of @Entity) • Asynchronous CallbackMonday, May 9, 2011 16
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×