mongoose-scroll

Mongoose scroll plugin.

Mongoose scroll plugin

npm install mongoose-scroll

Model:

var Mongoose = require('mongoose');
var MongooseScroll = require('mongoose-scroll');
 
var ArticleSchema = new Mongoose.Schema({
  title: String
});
 
ArticleSchema.plugin(MongooseScroll);
var Article = Mongoose.model('Article', ArticleSchema);

Controller:

Article.find({}).sort({'_id': -1}).scroll(request.query.cursor).exec(function(err, docs) {
  console.log(docs);
});

Model:

var CommentSchema = new Mongoose.Schema({
  body: String,
});
var Comment = Mongoose.model('Comment', CommentSchema);
 
// Article schema
var ArticleSchema = new Mongoose.Schema({
  title: String,
  comments: [{type: Mongoose.Schema.ObjectId, ref: 'Comment'}]
});
 
ArticleSchema.plugin(MongooseScroll);
var Article = Mongoose.model('Article', ArticleSchema);

Controller:

Article.findById(id, function(err, article) {
  article.scroll('comments', request.query.cursor).limit(25).exec(function(err, comments) {
    console.log(comments);
  });
});