I am using the linnovate MEAN boilerplate to build an application: https://github.com/linnovate/mean
With MongoDB I understand how to query a collection on the database and get the results via the command line such as:
db.articles.find({ 'title' : 'hello world'})
In the MEAN app the area I noticed for this type of querying is in the app/controllers/articles.js file:
/**
* List of Articles
*/
exports.all = function(req, res) {
Article.find().sort('-created').populate('user', 'name username').exec(function(err, articles) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(articles);
}
});
};
If I wanted to add a way of returning another list with a specific query how would I go about that?Here is the code I'm working on:
exports.all = function(req, res) {
Article.find().sort('-created').populate('user', 'name username').exec(function(err, articles) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(articles);
Article.find({ 'category' : 'hello world').sort('-created').populate('user', 'name username').exec(function(err, morearticles) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(morearticles);
}
});
}
});
};