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

Webinar Introduction to MongoDB's Java Driver

D8fc2580cfaca035f666d9e4ee79a7f7?s=47 mongodb
August 16, 2012
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.

D8fc2580cfaca035f666d9e4ee79a7f7?s=128

mongodb

August 16, 2012
Tweet

Transcript

  1. 1   MongoDB’s  Java  Driver  

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

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

     /  deserialization   •  Manage  cursors   •  Maintain  replica  set  awareness  
  4. 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  
  5. 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/  
  6. Encoding / Decoding BSON  interface  DBEncoder    interface  DBDecoder  

    DBObject  decode(  InputStream  in,              DBCollection  collection  );   int  writeObject(  OutputBuffer  buf,                                    BSONObject  o  );  
  7. On to the good stuff… Reading, Writing & Arithmetic

  8. A  simple  example…  

  9. Basics of Replication Node 1 Secondary Node 2 Secondary Node

    3 Primary Replication   Replication   Heartbeat  
  10. Strong Consistency Primary Secondary Secondary Read   Write   Client

     
  11. Eventual Consistency Primary Read   Write   Driver   Read

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

      •  SECONDARY     •  SECONDARY  PREFERRED     •  NEAREST    
  13. Using  Read   Preferences…  

  14. Writes & Durability •  Fire  and  forget     • 

    Wait  for  error   •  Wait  for  journal  commit   •  Wait  for  fsync   •  Wait  for  replication  to  secondary  
  15. Using  write  concerns…  

  16. 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    
  17. 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”   }  
  18. Using  tags…  

  19. Aggregation Framework •  Calculate  aggregate  values  without   having  to

     use  map-­‐reduce   •  Written  in  C++,  high  performance   •  Declarative,  no  javascript   •  Extensible,  new  operations  easily  added  
  20. Aggregation Operators •  $match •  $project •  $unwind •  $group

    •  $sort •  $skip •  $limit
  21. Aggregation Example sample document: {    "_id"  :   ObjectId("5029e745a0988a275aefd0c0"),

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

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

       "aggregate"  :  "scores"  ,            "pipeline"  :  [                    {  "$match"  :  {  "year"  :  "junior"}}  ,                  {  "$project"  :  {  "name"  :  1  ,  "score"  :  1  ,  "_id"  :  0}}  ,                    {  "$group"  :  {                            "_id"  :  "$name"  ,                            "average"  :  {  "$avg"  :  "$score"}                          }                  }          ]   }  
  24. The  aggregation  helper…  

  25. 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  
  26. Join  us!   We’re  Hiring!   Bryan.reinero@10gen.com