Using tailable cursors

juzerali edited this page Sep 13, 2012 · 2 revisions
Clone this wiki locally
skin = require "mongoskin"
db = skin.db "localhost:27017/local"

#Cursor on oplog (a capped collection) which maintains a history for replication
#oplog can be used only when replication is enabled
# Use oplog.rs instead of oplog.$main if you are using replica set

oplog = db.collection "oplog.$main"
cursor = oplog.find({'ns': "icanvc.projects"},{tailable: yes, awaitData: yes})

#Using cursor.nextObject will be slow
cursor.each (err, log)->
    console.error err if err
    console.log log if not err