Created
December 29, 2011 23:18
-
-
Save thegoleffect/1536656 to your computer and use it in GitHub Desktop.
[Reference][Snippet][MongooseJS]: Tailable cursor example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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