admin mongo s1 report

伍洋兄,辛苦拉下1954、1955两个订单下所有活动11月份独立转化和全部转化s1的统计情况,需要type字段

首选如下如下聚合语句:

db.conversion_20171101.aggregate([{$match:{offer_id:{$in:[1954,1955]}}},{$group : {_id : {"offer_id":"$offer_id","campaign_id":"$campaign_id","n_id":"$n_id","type":"$type","s1":"$s1"}, "campaign_id":{$first:"$campaign_id"},total : {$sum : 1}}},{$sort:{"campaign_id":1}}])

db.conversion_20171101.aggregate([{$match:{offer_id:1954}},{$group : {_id : {"offer_id":"$offer_id","campaign_id":"$campaign_id","n_id":"$n_id","type":"$type","s1":"$s1"}, total : {$sum : 1}}}])

db.conversion_20171101.aggregate([{$match:{offer_id:{$in:[1954,1955]}}},{$group : {_id : {"offer_id":"$offer_id","campaign_id":"$campaign_id","n_id":"$n_id","type":"$type","s1":"$s1"}, total : {$sum : 1}}}])

以下为统计整个月的s1的js文件 G:\SRAll\s1report.js:

load("C:\\Users\\administrator\\.mongorc.js")
var arr=new Array();
for(var i=30;i>0;i--)
{
var day=(i>9?i:"0"+i);
var collectionname="conversion_201711"+day;
arr.push(collectionname);
};
//for each array
for(var k in arr){
var collname=arr[k];
var collection=db.getCollection(collname);
var c=collection.aggregate([{$match:{offer_id:{$in:[1954,1955]}}},{$group : {_id : {"offer_id":"$offer_id","campaign_id":"$campaign_id","n_id":"$n_id","type":"$type","s1":"$s1"}, "campaign_id":{$first:"$campaign_id"},total : {$sum : 1}}},{$sort:{"campaign_id":1}}]);
printcwhile(c);
//print("coll name : " + collection + " aggregated");
//test to break in case of bad loop
//if(k>2)break;
}

注意此处使用了 printcwhile(c); 那么cmd下使用如下命令
mongo localhost:27017/mclog xx.js > s1report
导致报告中是json格式,需要使用java程序处理(python也可以,bash没试过)

你可能感兴趣的:(admin mongo s1 report)