In my MEAN app, I have a controller, which serves the following api:
app.get('/mongodata', function(req, res){
console.log('Request Successful');
console.log('_parsedUrl.query: ' + req._parsedUrl.query);
var url_parts = requestUrl.parse(req.url, true);
var query = url_parts.query;
var dataVersion = req.query.dataVersion;
MongoClient.connect(url, function (err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
console.log('Connection established to', url);
var collection = db.collection(query.collectionName);
collection.find({DataVersion: query.dataVersion}).toArray(function(err, docs) {
//console.log(docs);
res.json(docs);
assert.equal(null, err);
db.close();
});
}
});
});
What is the proper technique / syntax to add pagination capability to this api?