MongoDB 看起来像:
{ "_id" : ObjectId("503d5024ff9038cdbfcc9da4"),
"employee" : 61,
"department" : "Sales",
"amount" : 77,
"type" : "airfare"
}
在 mongoDB 控制台中,我可以通过两个参数(departments
和type
)聚合:
db.workers.aggregate(]{$group:{_id:{department:"$department",type:"$type"},amount_sum:{$sum:"$amount"}}}])
在java中是如何实现的?