How to Group mongodb - mapReduce output?

后端 未结 3 732
余生分开走
余生分开走 2020-12-11 22:19

i have a query regarding the mapReduce framework in mongodb, so i have a result of key value pair from mapReduce function , now i want to run the query on this output of map

3条回答
  •  一整个雨季
    2020-12-11 23:19

    I wrote a query using your data in aggregation as per my knowledge, there may be better way to solve this problem.

    var a=db.test.aggregate([{$match:{"value.count":{$lt:5}}},
                  { $group: { _id:"$value.count",total:{"$sum":1}}},
                 {$group:{_id:"less than 5",total:{$sum:"$total"}}}])              
    
    var b=db.test.aggregate([{$match:{"value.count":{$lt:10,$gt:5}}},
                { $group: { _id:"$value.count",total:{"$sum":1}}},
                {$group:{_id:"between 5 and 10",total:{$sum:"$total"}}}])
    
    var c=db.test.aggregate([{$match:{"value.count":{$lt:15,$gt:10}}},
           { $group: { _id:"$value.count",total:{"$sum":1}}},
           {$group:{_id:"between 10 and 15",total:{$sum:"$total"}}}])
    

    insert a, b, c into another collection

提交回复
热议问题