Skip to content

Instantly share code, notes, and snippets.

@andrewvc
Created August 26, 2010 02:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewvc/550650 to your computer and use it in GitHub Desktop.
Save andrewvc/550650 to your computer and use it in GitHub Desktop.
#Kind of like tail -f -n1
db = Mongo::Connection.new(mongo_hostname).db(mongo_dbname)
coll = db.collection(mongo_collection)
start_count = coll.count
tail = Mongo::Cursor.new(coll, :tailable => true, :order => [['$natural', 1]]).skip(start_count- 1)
loop do
if doc = tail.next_document
puts doc
else
sleep 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment