Skip to content

Instantly share code, notes, and snippets.

@thegoleffect
Created December 29, 2011 23:18
Show Gist options
  • Save thegoleffect/1536656 to your computer and use it in GitHub Desktop.
Save thegoleffect/1536656 to your computer and use it in GitHub Desktop.
[Reference][Snippet][MongooseJS]: Tailable cursor example
// This example shows how to use tailable cursors in MongoDB using mongoosejs
// IMPORTANT: The collection must be created as "capped" or this will raise err.
// At time of writing, there is no built-in way to create capped collection using MongooseJS.
var mongoose = require("mongoose");
mongoose.connect(connect_string);
Model = mongoose.model(model_name);
Model.connection.find(query, {tailable:true}, function(err, cursor){
if (err){
return console.log(err)
}
cursor.each(function(err, doc){
// do stuff to doc
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment