Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
MongoDB: ObjStorSol + Des+Map’n<br />Yeah, I shortened that… but not to OSSDnM<br />
…<br />AppServer - J2EE (JBoss, Resin)<br />Hosted AppServices - Google AppEngine<br />Datastore - Objectify (GAEJ ORM/ODM...
Basic Expectations<br />No transactions (but atomic updates)<br />Memory mapped data files<br />Document store<br />Fast-N...
What is the shell?<br />
What is it good for?<br />Debugging<br />Testing<br />Administration<br />Scripting Glue<br />Not building apps, probably…...
Shell Demo<br />
Single Collection, Inheritance<br />One – Many<br />Embedded<br />Reference<br />On the one -> Array of refs<br />On the M...
{<br />        _id : "scotthernandez",<br />        name : "Scott Hernandez",<br />desc : "that guy",<br />        groups ...
{        "_id" : "users",<br />        "desc" : "normal users“ },<br />{        "_id" : "fishermen",<br />        "desc" :...
blog =: { text: “I like to swim”, author: “scott”,<br />	comments: [<br />		{author:”ralph”, text:”me2”, <br />		replies:[...
Raw MongoDB Driver<br />Map<String, Object> view of objects<br />Rough but dynamic<br />Morphia (type-safe mapper)<br />PO...
BSON Package<br />Types<br />Encode/Decode<br />DBObject (Map<String, Object>)<br />Nested Maps<br />Directly encoded to b...
Data Types<br />int and long<br />Array/ArrayList<br />String<br />byte[] – binData<br />Double (IEEE 754 FP)<br />Date (m...
Morphia: MongoDB Mapper<br />Maps POJO<br />Type-safe<br />Access Patterns: DAO/Datastore/RollYourOwn<br />Data Types<br /...
Annotations<br />@Entity(“collectionName”)<br />@Id<br />@Transient (not transient)<br />@Indexed(…)<br />@Property(“field...
Lifecycle Events<br />@PrePersist<br />@PreSave<br />@PostPersist<br />@PreLoad<br />@PostLoad<br />EntityListeners<br />E...
Datastore Basics<br />get(class, id)<br />find(class, […])<br />save(entity, […])<br />delete(query)<br />getCount(query)<...
Basic POJO<br />@Entity<br />class Person {<br />	@Id <br />ObjectId name;<br />SexEnum sex;<br />@Indexed<br />Integer he...
Queries<br />Datastoreds = …<br />Query q = ds.createQuery(Person.class);<br />q.field(“height”).greaterThan(155).limit(5)...
Save whole object graphs (get/save)<br />Update parts (embedded objects)<br />Un/set fields<br />Push/pop arrays (lists)<b...
Update Operations<br />set(field, val)<br />unset(field)<br />inc(field, [val])<br />dec(field)<br />add(field, val)<br />...
Update existing props<br />Update w/new props<br />Examples<br />
Update<br />Datastoreds = …<br />Query q = ds.find(Person.class, “name”, “scott”);<br />UpdateOperationuo = ds.createUpdat...
Morphia Relationships Annotations<br />[@Embedded]<br />Load/Save with Entity<br />Update<br />@Reference<br />Stored as D...
Or… ScottHernandez@gmail.com<br />Questions?<br />
Upcoming SlideShare
Loading in …5
×

MongoDB Aug2010 SF Meetup

2,313 views

Published on

Published in: Technology
  • Be the first to comment

MongoDB Aug2010 SF Meetup

  1. 1. MongoDB: ObjStorSol + Des+Map’n<br />Yeah, I shortened that… but not to OSSDnM<br />
  2. 2. …<br />AppServer - J2EE (JBoss, Resin)<br />Hosted AppServices - Google AppEngine<br />Datastore - Objectify (GAEJ ORM/ODM)<br />MongoDB – Morphia (ODM)<br />Community Developer (and more)<br />How I got here…<br />
  3. 3. Basic Expectations<br />No transactions (but atomic updates)<br />Memory mapped data files<br />Document store<br />Fast-N-Loose by default (no safe/w/GLE)<br />Indexing order matters; query optimizer helps<br />One writer (serialized writes)<br />One JS thread (M/R, $where, group)<br />Many query threads (non-js)<br />BSON everywhere<br />
  4. 4. What is the shell?<br />
  5. 5. What is it good for?<br />Debugging<br />Testing<br />Administration<br />Scripting Glue<br />Not building apps, probably…<br />
  6. 6. Shell Demo<br />
  7. 7. Single Collection, Inheritance<br />One – Many<br />Embedded<br />Reference<br />On the one -> Array of refs<br />On the Many -> Add a ref field<br />Trees<br />Many – Many<br />Prob. best to store on only one side.<br />Designs<br />
  8. 8. {<br /> _id : "scotthernandez",<br /> name : "Scott Hernandez",<br />desc : "that guy",<br /> groups : [<br /> "users",<br /> "admins",<br /> "fishermen"<br /> ]<br />}<br />People - Groups<br />
  9. 9. { "_id" : "users",<br /> "desc" : "normal users“ },<br />{ "_id" : "fishermen",<br /> "desc" : "people who fish“ },<br />{ "_id" : "admins",<br /> "privledges" : 2,<br /> "desc" : "administrative users“ }<br />Group - People<br />
  10. 10. blog =: { text: “I like to swim”, author: “scott”,<br /> comments: [<br /> {author:”ralph”, text:”me2”, <br /> replies:[<br /> {author:”liz”, text:”doesn’t every1?”}<br /> ]},<br /> {author:”jeff”, text:”good to know”}<br /> ],<br />ts:Date(…)<br />}<br />Tree<br />
  11. 11. Raw MongoDB Driver<br />Map<String, Object> view of objects<br />Rough but dynamic<br />Morphia (type-safe mapper)<br />POJOs<br />Annotation based (similar to JPA)<br />Syntactic sugar and helpers<br />Others<br />Code generators, other jvm languages<br />Java Library Choices<br />
  12. 12. BSON Package<br />Types<br />Encode/Decode<br />DBObject (Map<String, Object>)<br />Nested Maps<br />Directly encoded to binary format (BSON)<br />MongoDB Package<br />Mongo<br />DBObject (BasicDBObject/Builder)<br />DB/DBColletion<br />DBQuery/DBCursor<br />MongoDB Java Driver<br />
  13. 13. Data Types<br />int and long<br />Array/ArrayList<br />String<br />byte[] – binData<br />Double (IEEE 754 FP)<br />Date (ms since epoch UTC)<br />Null<br />Boolean<br />JavaScript String<br />Regex<br />ObjectId (ts(4)+ host(3) + pid(2)+ incr(3) ) 12-byte<br />BSON Package<br />
  14. 14. Morphia: MongoDB Mapper<br />Maps POJO<br />Type-safe<br />Access Patterns: DAO/Datastore/RollYourOwn<br />Data Types<br />Low performance overhead<br />JPA like<br />Many concepts came from Objectify (GAE)<br />
  15. 15. Annotations<br />@Entity(“collectionName”)<br />@Id<br />@Transient (not transient)<br />@Indexed(…)<br />@Property(“fieldAlias”)<br />@AlsoLoad({aliases})<br />@Reference<br />@Serialized<br />[@Embedded]<br />
  16. 16. Lifecycle Events<br />@PrePersist<br />@PreSave<br />@PostPersist<br />@PreLoad<br />@PostLoad<br />EntityListeners<br />EntityInterceptor<br />
  17. 17. Datastore Basics<br />get(class, id)<br />find(class, […])<br />save(entity, […])<br />delete(query)<br />getCount(query)<br />update/First(query, upOps)<br />findAndModify/Delete(query, upOps)<br />
  18. 18. Basic POJO<br />@Entity<br />class Person {<br /> @Id <br />ObjectId name;<br />SexEnum sex;<br />@Indexed<br />Integer height;<br />} <br />
  19. 19. Queries<br />Datastoreds = …<br />Query q = ds.createQuery(Person.class);<br />q.field(“height”).greaterThan(155).limit(5);<br />for(Person p : q.fetch())<br /> print(p);<br />Person me = q.field(“name”).startsWith(“sc”).get();<br />
  20. 20. Save whole object graphs (get/save)<br />Update parts (embedded objects)<br />Un/set fields<br />Push/pop arrays (lists)<br />Increment numeric fields<br />Any combination of the above<br />Get/Save or Update<br />
  21. 21. Update Operations<br />set(field, val)<br />unset(field)<br />inc(field, [val])<br />dec(field)<br />add(field, val)<br />addAdd(field, vals)<br />removeFirst/Last(field)<br />removeAll(field, vals)<br />
  22. 22. Update existing props<br />Update w/new props<br />Examples<br />
  23. 23. Update<br />Datastoreds = …<br />Query q = ds.find(Person.class, “name”, “scott”);<br />UpdateOperationuo = ds.createUpdateOperations(cls)<br />uo.set(“city”, “seattle”).set(“lastUpdated”, new Date());<br />UpdateResults res = ds.update(q, uo);<br />if(res.getUpdatedCount() > 0)<br /> //do something?<br />
  24. 24. Morphia Relationships Annotations<br />[@Embedded]<br />Load/Save with Entity<br />Update<br />@Reference<br />Stored as DBRef(s)<br />Loaded with Entity<br />Not automatically saved<br />Key<T><br />Stored as DBRef(s)<br />Just a link, but resolvable by Datastore/Query<br />
  25. 25. Or… ScottHernandez@gmail.com<br />Questions?<br />

×