Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Webinar Introduction to MongoDB's Java Driver

mongodb
August 16, 2012
1.1k

Webinar Introduction to MongoDB's Java Driver

Bryan Reinero, Software Engineer, 10gen

A look into the internals of the Java driver for MongoDB. Learn how the driver supports replication, database connection pooling, and building queries. Also includes an introduction to the BSON (binary JSON) format for serialization of JSON objects, how the drivers handles write behavior with the use of write concerns and how the driver communicates to the database via the Mongo wire protocol. New features, fixes and improvements in the latest release will also be covered.

mongodb

August 16, 2012
Tweet

Transcript

  1. Topics we’ll cover •  Main  responsibilities  of  the  driver  

    •  New  features  for  version  2.9.0  
  2. Driver’s Main Responsibilities •  Manage  connections   •  BSON  serialization

     /  deserialization   •  Manage  cursors   •  Maintain  replica  set  awareness  
  3. Connection Management /**  The  mechanism  managing  the  pool  */  

    public  class  DBPortPool  extends  SimplePool<DBPort>   /**  database  connection  with  internal  pooling  */   public  class  Mongo   /**  Various  settings  for  the  driver  */   public  class  MongoOptions  
  4. Wire Protocol •  TCP/IP  socket  based  request/response   •  Exchanges

     BSON  objects  between  client  &   server   •  BSON  –  a  traversable,  binary  encoded   serialization  of  JSON  documents     •  BSON  is  the  primary  data  representation  in   MongoDB   http://bsonspec.org/  
  5. Encoding / Decoding BSON  interface  DBEncoder    interface  DBDecoder  

    DBObject  decode(  InputStream  in,              DBCollection  collection  );   int  writeObject(  OutputBuffer  buf,                                    BSONObject  o  );  
  6. Basics of Replication Node 1 Secondary Node 2 Secondary Node

    3 Primary Replication   Replication   Heartbeat  
  7. Eventual Consistency Primary Read   Write   Driver   Read

      Secondary Secondary Client  Application  
  8. Read Preferences •  PRIMARY     •  PRIMARY  PREFERRED  

      •  SECONDARY     •  SECONDARY  PREFERRED     •  NEAREST    
  9. Writes & Durability •  Fire  and  forget     • 

    Wait  for  error   •  Wait  for  journal  commit   •  Wait  for  fsync   •  Wait  for  replication  to  secondary  
  10. Tagging •  Each  node  within  a  replica  set  can  be

      marked  with  descriptors  called  tags     •  Tags  can  indicate  a  node’s  location,   membership  in  a  set,  or  other   characteristics     •  Use  tags  to  target  specific  nodes  for  read   or  write  operations    
  11. Using Tags Node 1 Node 2 Node 3 tags"  :

     {   "datacenter"  :  "Los  Angeles”,   "region"  :  "US_West”   }   tags"  :  {   "datacenter"  :”San  Jose”,   "region"  :  ”US_West”   }   tags"  :  {   "datacenter"  :”Richmond”,   "region"  :  "US_East”   }  
  12. Aggregation Framework •  Calculate  aggregate  values  without   having  to

     use  map-­‐reduce   •  Written  in  C++,  high  performance   •  Declarative,  no  javascript   •  Extensible,  new  operations  easily  added  
  13. Aggregation Example sample document: {    "_id"  :   ObjectId("5029e745a0988a275aefd0c0"),

       "name"  :  "quiz",    "score"  :  99,    "student"  :  7,    "year"  :  "junior"   }  
  14. Pipelining Operations $match $project $group $match  :  {  year  :

     'junior'  }     $project  :  {  name  :  1,  score  :  1  }     $group:  {            _id:  '$name',          average:  {  $avg:  '$score'  }   }  
  15. What the command looks like… {        

       "aggregate"  :  "scores"  ,            "pipeline"  :  [                    {  "$match"  :  {  "year"  :  "junior"}}  ,                  {  "$project"  :  {  "name"  :  1  ,  "score"  :  1  ,  "_id"  :  0}}  ,                    {  "$group"  :  {                            "_id"  :  "$name"  ,                            "average"  :  {  "$avg"  :  "$score"}                          }                  }          ]   }  
  16. There’s plenty more!... •  Tutorials   http://www.mongodb.org/display/DOCS/Java +Tutorial   • 

    Javadocs  http://api.mongodb.org/java/current/   •  Jira   https://jira.mongodb.org/secure/Dashboard.jspa