2. … AppServer - J2EE (JBoss, Resin) Hosted AppServices - Google AppEngine Datastore - Objectify (GAEJ ORM/ODM) MongoDB – Morphia (ODM) Community Developer (and more) How I got here…
3. Basic Expectations No transactions (but atomic updates) Memory mapped data files Document store Fast-N-Loose by default (no safe/w/GLE) Indexing order matters; query optimizer helps One writer (serialized writes) One JS thread (M/R, $where, group) Many query threads (non-js) BSON everywhere
7. Single Collection, Inheritance One – Many Embedded Reference On the one -> Array of refs On the Many -> Add a ref field Trees Many – Many Prob. best to store on only one side. Designs
8. { _id : "scotthernandez", name : "Scott Hernandez", desc : "that guy", groups : [ "users", "admins", "fishermen" ] } People - Groups
10. blog =: { text: “I like to swim”, author: “scott”, comments: [ {author:”ralph”, text:”me2”, replies:[ {author:”liz”, text:”doesn’t every1?”} ]}, {author:”jeff”, text:”good to know”} ], ts:Date(…) } Tree
11. Raw MongoDB Driver Map<String, Object> view of objects Rough but dynamic Morphia (type-safe mapper) POJOs Annotation based (similar to JPA) Syntactic sugar and helpers Others Code generators, other jvm languages Java Library Choices
13. Data Types int and long Array/ArrayList String byte[] – binData Double (IEEE 754 FP) Date (ms since epoch UTC) Null Boolean JavaScript String Regex ObjectId (ts(4)+ host(3) + pid(2)+ incr(3) ) 12-byte BSON Package
14. Morphia: MongoDB Mapper Maps POJO Type-safe Access Patterns: DAO/Datastore/RollYourOwn Data Types Low performance overhead JPA like Many concepts came from Objectify (GAE)
18. Basic POJO @Entity class Person { @Id ObjectId name; SexEnum sex; @Indexed Integer height; }
19. Queries Datastoreds = … Query q = ds.createQuery(Person.class); q.field(“height”).greaterThan(155).limit(5); for(Person p : q.fetch()) print(p); Person me = q.field(“name”).startsWith(“sc”).get();
20. Save whole object graphs (get/save) Update parts (embedded objects) Un/set fields Push/pop arrays (lists) Increment numeric fields Any combination of the above Get/Save or Update
24. Morphia Relationships Annotations [@Embedded] Load/Save with Entity Update @Reference Stored as DBRef(s) Loaded with Entity Not automatically saved Key<T> Stored as DBRef(s) Just a link, but resolvable by Datastore/Query