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

Real Time Analytics with MongoDB

Real Time Analytics with MongoDB

Presented at the Thames Valley, and later the London, MongoDB User Group in 2012. Really simple way to stream data from MongoDB for graphical visualisation in a browser using D3.

9d7ffb8ce4ac498a5a1a50697b3d1a3a?s=128

Julian Browne

May 31, 2012
Tweet

Transcript

  1. simple Real Time Analytics With MongoDB

  2. inspired by http://hummingbirdstats.com/

  3. more at https://devcenter.heroku.com/articles/realtime-polyglot-app-node-ruby-mongodb-socketio

  4. PS - code on github https://github.com/julianbrowne/rtsdemo

  5. Make a capped collection Put stuff in Query it with

    a tailable cursor See stuff come out Send it somewhere useful Steps
  6. db.createCollection("name", {capped:true, size:1000}); Fixed size (bytes) or docs (sort of)

    Loop-around writes A few constraints can’t delete can’t do collection.remove() can’t grow doc size by default no _id index no _id uniqueness Make a Capped Collection
  7. c = db.collection.find({}) .addOption(2) // tailable .addOption(32); // wait The

    Tailable Cursor for(i=0;i<5;i++) { while(c.hasNext()) { var doc = c.next(); printjson( doc ); } }
  8. Put stuff in / get stuff out read writes W

    R
  9. Send it somewhere useful W listener web socket sswatcher (8011)

    server (8010) shell HTML5 D3 / JS HTTP
  10. Replica Set Powered by the Oplog Knows All Sees All

    Capped Collection Exemplar
  11. See All W listener web socket rswatcher (8012) server (8010)

    shell HTML5 D3 / JS HTTP