2017-02-28 62 views
0

因此,我有一个应用程序,需要根据时间框架显示一些报告。Laravel用于生成特定时间的报告

因此,报告将基于发生的事件 - 成功率并使用MongoDB。

所以这些将是我的报告参数。

Status     | Total | Success | Failed | Success % 

<5 Min     50  40  10 
>5 min <15 min   --  --  -- 
>15 min <hour    --  --  -- 

所以我的问题是如何找到的所有记录,它只需不到5分钟,计算总,算上失败了,算成功。

我的查询在下面给出,所以根据日期范围,首先我必须对记录进行排序,之后,我不知道如何找到created_at和updated_at之间的区别,它具有状态成功,时间差是少于5分钟,5至15分钟等等。

//convert the date to ISO to search in mongo 
$from = Carbon::createFromFormat('Y-m-d', '2017-02-20'); 
$to  = Carbon::createFromFormat('Y-m-d', '2017-02-21'); 

//select the sutiable app 
$query = MyCollection::where('app_id', '12345'); 

//refine the results to the only selected date range. 
//tried whereBetween here, but not seems to be working, 
//hence used chained where 

$filter_dates = $query->where('created_at', '>=', $from) 
     ->where('created_at', '<=', $to); 


//Here I have to select the records like where created_at 
//and updated_at difference is like <5 mins, then next to 
//>5 min and <15 mins and so on. I am struck here. 

$filter_by_time = $filter_dates-> 

也请让我知道是否有更好的方法来实现我在做什么。

+0

包括你的表结构 – Beginner

回答

0

如何添加原始查询?

MyCollection::whereRaw('(updated_at - created_at) < ?', 300)->get(); 

我诚恳不知道它是如何工作的MongoDB与...