// 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']
]);
});
}
'웹개발 > PHP' 카테고리의 다른 글
centos에 php-mongodb driver 설치 (0) | 2020.05.27 |
---|---|
CentOS 7.8에서 php7.3 +nginx+php-fpm 설치 (0) | 2020.05.26 |
php 배열을 js 파일로 전달하는 방법들(Chart.js 이용하다가,,) (0) | 2020.05.20 |