Skip to content

Instantly share code, notes, and snippets.

@jakecraige
Created January 24, 2014 07:50
Show Gist options
  • Save jakecraige/8593633 to your computer and use it in GitHub Desktop.
Save jakecraige/8593633 to your computer and use it in GitHub Desktop.
function getAll(collection, res){
collection.list(function(err, resModels, options){
var results = [], pages;
if(err) {
console.log(err);
res.send(500);
}
console.log('page 1');
results.push(resModels);
pages = Number(options.pages)
if(pages > 1) {
for(var i = 2; i < pages; i++) {
collection.list({page: i}, function(err, pageModels){
console.log('page ', i);
if(err) { throw err; }
console.log(pageModels.length);
results.push(pageModels);
if(i === pages) {
res.send(_.flatten(results));
}
});
}
} else {
res.send(_.flatten(results));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment