javascript - how to do maths in mongoose.js query -


i have multiple rows , return data league table , ordered football league table.

my data in multiple rows each game played as:

{     "_id" : objectid("55d0f8a6bd0782b480dc4941"),     "venue" : "h",     "game_id" : objectid("55d0f8a6bd0782b480dc48f9"),     "date" : isodate("2015-04-25t14:00:00.000z"),     "gd" : 0,     "ga" : 1,     "gf" : 1,     "points" : 1,     "team_id" : objectid("55d0f8a6bd0782b480dc48f1"),     "__v" : 0 } 

i can see no way maths inside of query , return calculated values of points given team_id.

is there math in mongoose group in mysql?

yes there is, can use http://mongoosejs.com/docs/api.html#aggregate_aggregate-group , $sum http://docs.mongodb.org/manual/reference/operator/aggregation/sum/ sum of points on each team

 your-model-name.aggregate([     {         $group: {             _id: '$team_id',               total: {$sum: "$points"}         }     } ], function (err, result) {     if (err) {         // error ....     } else {         // result     } }); 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -