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

How MongoDB Works

How MongoDB Works

Deck for a short talk I've given on a EPAM Software Engineering Conference 2013.

Uladzimir Mihura

February 01, 2013
Tweet

More Decks by Uladzimir Mihura

Other Decks in Technology

Transcript

  1. Data Model: Document oriented {    _id:  1,    name:

     {        first:  'Michael',        last:  'Faraday'    },    birth:  new  Date('Sep  22,  1791'),    death:  new  Date('Aug  25,  1867'),    contribs:  ['Chemistry',  'Electricity',  'Diamagnetism'] }
  2. • find, findOne • accepts a conditions object • regex,

    strings, numbers, etc... • rich operators • $lt, $gt, $or, $and, $in, $ne, ... • projections • specify fields to return Reading: Dynamic Queries
  3. Reading: Indexes • B-Tree • multiply fields • options •

    unique • sparse • 2d • full text search (≥2.4) Di Lu Rh B C Cr Zo St Sa Ka H F B C Cr
  4. • Errors ignored (even network errors) • Unacknowledged (fire &

    forget) • Acknowledged (write accepted) • Journaled • Propagated to the replica set members Writing: Write Concerns
  5. Writing: Isolation db.foo.update(   {  field1  :  1  ,  $isolated

     :  1  },   {  $inc  :  {  field2  :  1  }  }  , {  multi:  true  }   )
  6. Storage: Directory Layout -­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl  

         64M  Jan  28  14:38  foo.0 -­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      128M  Jan  28  14:26  foo.1 -­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      256M  Jan  28  14:31  foo.2 -­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      512M  Jan  28  14:38  foo.3 -­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      1.0G  Jan  28  14:38  foo.4 -­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      2.0G  Jan  28  14:38  foo.5 -­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl        16M  Jan  28  14:38  foo.ns • Separate files per database • Aggressive preallocation
  7. Scaling: Replication Node 3 Primary Node 1 Secondary Node 2

    Secondary Replication Replication client read read read write
  8. Scaling: Replication Node 3 Primary Node 1 Primary Node 2

    Secondary Replication client read read write
  9. Scaling: Replication Node 3 Secondary Node 1 Primary Node 2

    Secondary Replication client read read write read Replication
  10. Scaling: Sharding Client mongos mongos ... mongod mongod mongod Replica

    Set mongod mongod mongod Replica Set mongod mongod mongod Replica Set Shards mongod mongod mongod Config Servers