MongoDB Aug2010 SF Meetup
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,998
On Slideshare
1,998
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
17
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. MongoDB: ObjStorSol + Des+Map’n
    Yeah, I shortened that… but not to OSSDnM
  • 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
  • 4. What is the shell?
  • 5. What is it good for?
    Debugging
    Testing
    Administration
    Scripting Glue
    Not building apps, probably…
  • 6. Shell Demo
  • 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
  • 9. { "_id" : "users",
    "desc" : "normal users“ },
    { "_id" : "fishermen",
    "desc" : "people who fish“ },
    { "_id" : "admins",
    "privledges" : 2,
    "desc" : "administrative users“ }
    Group - People
  • 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
  • 12. BSON Package
    Types
    Encode/Decode
    DBObject (Map<String, Object>)
    Nested Maps
    Directly encoded to binary format (BSON)
    MongoDB Package
    Mongo
    DBObject (BasicDBObject/Builder)
    DB/DBColletion
    DBQuery/DBCursor
    MongoDB Java Driver
  • 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)
  • 15. Annotations
    @Entity(“collectionName”)
    @Id
    @Transient (not transient)
    @Indexed(…)
    @Property(“fieldAlias”)
    @AlsoLoad({aliases})
    @Reference
    @Serialized
    [@Embedded]
  • 16. Lifecycle Events
    @PrePersist
    @PreSave
    @PostPersist
    @PreLoad
    @PostLoad
    EntityListeners
    EntityInterceptor
  • 17. Datastore Basics
    get(class, id)
    find(class, […])
    save(entity, […])
    delete(query)
    getCount(query)
    update/First(query, upOps)
    findAndModify/Delete(query, upOps)
  • 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
  • 21. Update Operations
    set(field, val)
    unset(field)
    inc(field, [val])
    dec(field)
    add(field, val)
    addAdd(field, vals)
    removeFirst/Last(field)
    removeAll(field, vals)
  • 22. Update existing props
    Update w/new props
    Examples
  • 23. Update
    Datastoreds = …
    Query q = ds.find(Person.class, “name”, “scott”);
    UpdateOperationuo = ds.createUpdateOperations(cls)
    uo.set(“city”, “seattle”).set(“lastUpdated”, new Date());
    UpdateResults res = ds.update(q, uo);
    if(res.getUpdatedCount() > 0)
    //do something?
  • 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
  • 25. Or… ScottHernandez@gmail.com
    Questions?