Laravel 5如何在两个日期之间进行搜索?

时间:2015-11-13 16:10:11

标签: mongodb laravel laravel-5

我正在使用https://github.com/jenssegers/laravel-mongodb库来处理mongodb。我怎样才能在两个日期之间进行搜索?

我已经用" Carbon"和#34; Mongodate"但他们都没有回馈任何东西。

模型文件:

namespace App;
use Jenssegers\Mongodb\Model as Eloquent;

class Motors extends Eloquent{
    protected $collection = 'motors';
    protected $dates = array('date');
}

控制器:

public function found(Request $request) {
    $q = Motors::query();
    if (Input::has('from_year') and Input::has('from_month') and Input::has('to_year') and Input::has('to_month')) {
        $from_year = $request::get('from_year');
        $from_month = $request::get('from_month'); 
        $to_year = $request::get('to_year');          
        $to_month = $request::get('to_month');

        //$from_date = Carbon::createFromDate((int)$from_year, 1, 1);
        //$to_date = Carbon::createFromDate((int)$to_year, 12, 31);

        $from_date = new MongoDate(strtotime("2005-01-03T00:00:00.000+0000"));
        $to_date = new MongoDate(strtotime("2016-01-03T00:00:00.000+0000"));

        $q->whereBetween('date', array($from_date->sec, $to_date->sec));
    }
    $motors = $q->paginate(10);
    return view('pages.motors_found', compact('motors'));
}

我在mongodb中记录查询,这是由mongodb的日志给出的:

2015-11-13T16:42:22.144+0100 I QUERY    [conn5] query laramotor.motors query: { date: { $gte: 1104710400, $lte: 1451779200 } } planSummary: COLLSCAN ntoreturn:0 ntoskip:0 nscanned:0 nscannedObjects:3077 keyUpdates:0 writeConflicts:0 numYields:24 nreturned:0 reslen:20 locks:{ Global: { acquireCount: { r: 50 } }, MMAPV1Journal: { acquireCount: { r: 25 } }, Database: { acquireCount: { r: 25 } }, Collection: { acquireCount: { R: 25 } } } 2ms

可能是什么问题?

0 个答案:

没有答案