// input
var date = 20200602
var period = 7;

//temp 미리 만들어놨음 - 나중에 ttl index
var temp_cnt = db.temp.count();
var array = new Array();

for(var i=0; i<period; i++){
var stage = db.test_logs.aggregate([
	{$match: {rday:20200602+i}},
    {$lookup:{
    	from: "temp",
        localField: "userid",
        foreignField: "userid",
        as: "test"
    }}
]);

var stage_cnt = stage._batch.length
array.push(stage_cnt/temp_cnt*100);
}
print(array)
static function lookUpByStage($date, $i){

        return LoginLog::on('mongodbGomLogs')->raw(function($collection) use ($date, $i){
           return $collection->aggregate([
               ['$match'=>['rday'=> $date+$i]],
               ['$lookup'=>[
                    'from'=>'temp',
                    'localField'=>'userid',
                    'foreignField'=>'userid',
                    'as'=>'test'
                ]],
               ['$count'=>'userid']
           ]);
        });

    }

 

+ Recent posts