I'm creating a RESTful API that will return documents in a MongoDB collection. Being RESTful, I would like to limit the number of documents returned to 25, and then let the client ask for the next 25, and then the next, and so on until all documents have been read. Using find() I am able to get 'all' documents in a collection, and using find().limit() I can limit it to 25, but it will always get the first 25. Are there any good code examples out there showing how to remember where you left off in the find() so that the second call to find will return the next 25 documents in the collection? My code so far ...
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
Transaction.find(function (err, transactions) {
if (err) {
mongoose.connection.close();
res.send('FAIL');
} else {
mongoose.connection.close();
res.send(transactions);
}
}).limit(25);
});
tx!