Slide 1

Slide 1 text

1   MongoDB’s  Java  Driver  

Slide 2

Slide 2 text

Topics we’ll cover •  Main  responsibilities  of  the  driver   •  New  features  for  version  2.9.0  

Slide 3

Slide 3 text

Driver’s Main Responsibilities •  Manage  connections   •  BSON  serialization  /  deserialization   •  Manage  cursors   •  Maintain  replica  set  awareness  

Slide 4

Slide 4 text

Connection Management /**  The  mechanism  managing  the  pool  */   public  class  DBPortPool  extends  SimplePool   /**  database  connection  with  internal  pooling  */   public  class  Mongo   /**  Various  settings  for  the  driver  */   public  class  MongoOptions  

Slide 5

Slide 5 text

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/  

Slide 6

Slide 6 text

Encoding / Decoding BSON  interface  DBEncoder    interface  DBDecoder   DBObject  decode(  InputStream  in,              DBCollection  collection  );   int  writeObject(  OutputBuffer  buf,                                    BSONObject  o  );  

Slide 7

Slide 7 text

On to the good stuff… Reading, Writing & Arithmetic

Slide 8

Slide 8 text

A  simple  example…  

Slide 9

Slide 9 text

Basics of Replication Node 1 Secondary Node 2 Secondary Node 3 Primary Replication   Replication   Heartbeat  

Slide 10

Slide 10 text

Strong Consistency Primary Secondary Secondary Read   Write   Client  

Slide 11

Slide 11 text

Eventual Consistency Primary Read   Write   Driver   Read   Secondary Secondary Client  Application  

Slide 12

Slide 12 text

Read Preferences •  PRIMARY     •  PRIMARY  PREFERRED     •  SECONDARY     •  SECONDARY  PREFERRED     •  NEAREST    

Slide 13

Slide 13 text

Using  Read   Preferences…  

Slide 14

Slide 14 text

Writes & Durability •  Fire  and  forget     •  Wait  for  error   •  Wait  for  journal  commit   •  Wait  for  fsync   •  Wait  for  replication  to  secondary  

Slide 15

Slide 15 text

Using  write  concerns…  

Slide 16

Slide 16 text

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    

Slide 17

Slide 17 text

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”   }  

Slide 18

Slide 18 text

Using  tags…  

Slide 19

Slide 19 text

Aggregation Framework •  Calculate  aggregate  values  without   having  to  use  map-­‐reduce   •  Written  in  C++,  high  performance   •  Declarative,  no  javascript   •  Extensible,  new  operations  easily  added  

Slide 20

Slide 20 text

Aggregation Operators •  $match •  $project •  $unwind •  $group •  $sort •  $skip •  $limit

Slide 21

Slide 21 text

Aggregation Example sample document: {    "_id"  :   ObjectId("5029e745a0988a275aefd0c0"),    "name"  :  "quiz",    "score"  :  99,    "student"  :  7,    "year"  :  "junior"   }  

Slide 22

Slide 22 text

Pipelining Operations $match $project $group $match  :  {  year  :  'junior'  }     $project  :  {  name  :  1,  score  :  1  }     $group:  {            _id:  '$name',          average:  {  $avg:  '$score'  }   }  

Slide 23

Slide 23 text

What the command looks like… {            "aggregate"  :  "scores"  ,            "pipeline"  :  [                    {  "$match"  :  {  "year"  :  "junior"}}  ,                  {  "$project"  :  {  "name"  :  1  ,  "score"  :  1  ,  "_id"  :  0}}  ,                    {  "$group"  :  {                            "_id"  :  "$name"  ,                            "average"  :  {  "$avg"  :  "$score"}                          }                  }          ]   }  

Slide 24

Slide 24 text

The  aggregation  helper…  

Slide 25

Slide 25 text

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  

Slide 26

Slide 26 text

Join  us!   We’re  Hiring!   [email protected]