You can see Mongoose streaming capabilities:
var stream = mongoose.model('Post').find({tags: 'Adventure'}).stream();
stream.on('data', function (post) {
console.log(post.title);
});
QueryStream, stream(), Node.js 'Stream, , pause resume, .
[]
, , , QueryStream, , , . https://gist.github.com/3453567; Gist (git://gist.github.com/3453567.git), npm install, node index.js, http://localhost:3000. , , .
- :
-, " " :
var UserSchema = new mongoose.Schema({
user: String,
lastQuote: { type: mongoose.Schema.Types.ObjectId, ref: 'Quote' }
});
, User.findOne().populate('lastQuote'), lastQuote , , Quote, , MongoDB ( ObjectId).
next() Quote - :
QuoteSchema.methods.next = function(cb) {
var model = this.model("Quote");
model.findOne().where('_id').gt(this._id).exec(function(err, quote) {
if (err) throw err;
if (quote) {
cb(null, quote);
} else {
model.findOne(cb);
}
});
};
, .
, - .