我正在实施一个商店经理,我需要通过mapreduce和appgregation访问我的mongodb。我访问的这个ShopList看起来像这样,
{
//this is one shop
{ //key & unique
id: '0000001',
//device count actually
deviceVoltage:{high:1200, mid: 2400, low: 2300},
lastUpdatedTime: Date(2019,1,1),
//shop name
name:'test1'
},
//this is another shop
{
id:'0000002',
deviceVoltage:{high:2000, mid: 100, low: 3000},
lastUpdatedTime: Date(2019,1,2),
name:'test2'
},
...
}
由于某种原因,我必须应用过滤器,例如服务器端的高电压比过滤器。也就是说,我需要为这些属性设置上限和下限,并将其应用于每个商店。由于此操作的复杂性,我必须使用mapreduce和聚合。让我们做一个真实的案例。
task: Please filter all shops and return shops with
(1) device high voltage ratio>10%,
(2) shop name contains keyword 'pharmac' and
(3) last updated time is in a week.
Step1: sum the device voltage array, and calcualte the ratio of [high]
(done by mapReduce. the collection contains an array of many maps of
shop_id and the calculated high-voltage device ratio)
Step2: get a collection from Step1, use mongoDb query to filter shop names and last updated time
(done by aggregation and pipe,
the collection contains an array of shops objects)
Step3: intersect the collection from Step1 and the result from Step2 by the shop id
(but, how to do this?)
有没有一种方法可以很好地完成Step3?
欢迎提出任何想法。