Organizational Research By

Surprising Reserch Topic

calculated group by fields in mongodb


calculated group by fields in mongodb  using -'java,mongodb,spring-data,aggregation-framework'

For this example from the MongoDB documentation, how do I write the query using MongoTemplate?

db.sales.aggregate(
   [
      {
        $group : {
           _id : { month: { $month: "$date" }, day: { $dayOfMonth: "$date" }, year: { $year: "$date" } },
           totalPrice: { $sum: { $multiply: [ "$price", "$quantity" ] } },
           averageQuantity: { $avg: "$quantity" },
           count: { $sum: 1 }
        }
      }
   ]
)


Or in general, how do I group by a calculated field?
    
asked Sep 22, 2015 by yogeshplv
0 votes
16 views



Related Hot Questions



Government Jobs Opening


...