I am building an application using MongoDB, Angular, Express and Node (MEAN stack).
I used the MEAN.JS generator to search for my application.
I will use the article module as a link.
Suppose I have 7,000 entries in my collection of articles, and each entry has a date associated with it. It is inefficient to load all 7000 records into memory every time I load a page to view records in a table, and because of this I see terrible performance losses. For this reason, I would just like to download records with a date in the range from 1 month to (1 year from the moment) and display them in a table. I can currently do this with the following:
In my .client.controller.js articles:
$scope.find = function() { $articles = Articles.query(); };
... and in my .server.controller.js articles:
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); } }); };
The problem is that this is not a dynamic way to do something. In other words, I want the user to be able to specify how far back and how far forward they want to see.
How can I bind to variables (for example, "aYearFromNow" and "aMonthAgo") in my client view that will change the request parameters in my server controller?
javascript angularjs mongodb express meanjs
caseyhanley
source share