I am currently developing an application using the MEAN stack - MongoDB, Angular, Express, and Node.js.
To kickstart my project, I utilized the MEAN.JS generator to set up the initial structure of my application.
The articles module within my application serves as a model for reference.
As my articles collection grows to 7000 records, each with an associated date value, I noticed a decline in performance due to loading all records into memory. To address this issue, I aim to optimize by only displaying records within the date range of (1 Month Ago) to (1 Year From Now) in a table view. Currently, I achieve this by:
In the articles.client.controller.js file:
$scope.find = function() {
$articles = Articles.query();
};
...and within articles.server.controller.js:
var now = new Date();
var aYearFromNow = new Date(now.getTime() + 86400000*365); //add a year
var aMonthAgo = new Date(now.getTime() - 86400000*30); //subtract roughly a month
exports.list = function(req, res) { Article.find().where('date').lt(aYearFromNow).gt(aMonthAgo).sort('-created').populate('user', 'displayName').exec(function(err, articles) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
res.jsonp(articles);
}
});
};
However, this approach lacks flexibility. My goal is to empower users to specify their desired date ranges dynamically.
How can I establish bindings in the client view to adjust query parameters in the server controller, such as 'aYearFromNow' and 'aMonthAgo'?