Mongo Playground

Configuration

[{event_type:"view",product:"water_heater"},{event_type:"view",product:"water_heater"},{event_type:"view",product:"water_heater"},{event_type:"purchase",product:"television"},{event_type:"view",product:"television"},{event_type:"view",product:"television"},{event_type:"view",product:"television"},{event_type:"purchase",product:"television"}]

Query

db.collection.aggregate([{$group:{_id:"$product",purchases:{$sum:{$cond:[{$eq:["$event_type","purchase"]},1,0]}},views:{$sum:{$cond:[{$eq:["$event_type","view"]},1,0]}}}},{$project:{_id:0,product:"$_id",ratio:{$divide:["$purchases","$views"]}}},{$sort:{ratio:-1}}])

Result