How to render aggregate result using MongoDB and Node js in Browser using Handlebars template?

7 Views Asked by At

I want to render the result of an aggregated data from MongoDB and be able to render it in Browser in the table using Handlebars Template. Sorry I am new to Handlebars

Below is my code:

var leastArticleRevision = [
        {'$group':{'_id':"$title", 'numOfEdits': {$sum:1}}},
        {'$sort':{numOfEdits:1}},
        {'$limit':5}    
    ];

var test = Revision.aggregate(leastArticleRevision, function(err, results){
    if (err){
        console.log("Aggregation Error")
    }else{
        console.log("The least editted articles are: ");
        console.log(results)
    }
})


router.get('/', function(req, res){
    res.render('index',{
        content: "Hello World",
        test: test
    });
});
0

There are 0 best solutions below