Más contenido relacionado La actualidad más candente (20) Similar a Mongo db with spring data document (20) Mongo db with spring data document2. <<interface>>
@Autowired
Mongo
Operations
Bean
Mongo
Template
Bean
MongoDB
Driver
Monday, May 9, 2011 2
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. 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. 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. 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
8. Save
> db.things.save({ name: "mongo" })
> t = { x : 3 }
{ "x" : 3 }
> db.things.save(t)
Monday, May 9, 2011 8
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. 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
12. MongoTemplate
• Document databases extension to Spring
Programming Model
• SPEL
• DataException hierarchy
• IoC Configuration
Monday, May 9, 2011 12
14. <<interface>>
Mongo
Mongo
@Autowired Repository
Operations
Mongo
Criteria
Bean
Mongo
Template
Bean
MongoDB
Driver
Monday, May 9, 2011 14
16. • MongoRepository
• Method name based Query
• @Query, QueryDSL
• Criteria, Predication Support
• GPS Query
• Mapping
• @Document(Instead of @Entity)
• Asynchronous Callback
Monday, May 9, 2011 16