• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
MongoDB Aug2010 SF Meetup
 

MongoDB Aug2010 SF Meetup

on

  • 1,877 views

 

Statistics

Views

Total Views
1,877
Views on SlideShare
1,877
Embed Views
0

Actions

Likes
2
Downloads
17
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    MongoDB Aug2010 SF Meetup MongoDB Aug2010 SF Meetup Presentation Transcript

    • MongoDB: ObjStorSol + Des+Map’n
      Yeah, I shortened that… but not to OSSDnM

    • AppServer - J2EE (JBoss, Resin)
      Hosted AppServices - Google AppEngine
      Datastore - Objectify (GAEJ ORM/ODM)
      MongoDB – Morphia (ODM)
      Community Developer (and more)
      How I got here…
    • 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
    • What is the shell?
    • What is it good for?
      Debugging
      Testing
      Administration
      Scripting Glue
      Not building apps, probably…
    • Shell Demo
    • 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
    • {
      _id : "scotthernandez",
      name : "Scott Hernandez",
      desc : "that guy",
      groups : [
      "users",
      "admins",
      "fishermen"
      ]
      }
      People - Groups
    • { "_id" : "users",
      "desc" : "normal users“ },
      { "_id" : "fishermen",
      "desc" : "people who fish“ },
      { "_id" : "admins",
      "privledges" : 2,
      "desc" : "administrative users“ }
      Group - People
    • 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
    • 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
    • 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
    • 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
    • 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)
    • Annotations
      @Entity(“collectionName”)
      @Id
      @Transient (not transient)
      @Indexed(…)
      @Property(“fieldAlias”)
      @AlsoLoad({aliases})
      @Reference
      @Serialized
      [@Embedded]
    • Lifecycle Events
      @PrePersist
      @PreSave
      @PostPersist
      @PreLoad
      @PostLoad
      EntityListeners
      EntityInterceptor
    • Datastore Basics
      get(class, id)
      find(class, […])
      save(entity, […])
      delete(query)
      getCount(query)
      update/First(query, upOps)
      findAndModify/Delete(query, upOps)
    • Basic POJO
      @Entity
      class Person {
      @Id
      ObjectId name;
      SexEnum sex;
      @Indexed
      Integer height;
      }
    • 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();
    • 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
    • Update Operations
      set(field, val)
      unset(field)
      inc(field, [val])
      dec(field)
      add(field, val)
      addAdd(field, vals)
      removeFirst/Last(field)
      removeAll(field, vals)
    • Update existing props
      Update w/new props
      Examples
    • 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?
    • 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
    • Or… ScottHernandez@gmail.com
      Questions?