I want to select documents that are specified on a given date of the date, for example between
$from_date : "2017-01-07 09:08:59" To `$to_date : "2017-08-09 09:08:59"`
I am using the laravel framework and the janssegers / laravel-mongodb mongodb driver to run my request. And this is my original request:
$normal_banners = BannerView::raw(function ($collection) use ($id, $from_date, $to_date) {
$conditions = [
["camp_id" => ['$eq' => $id]],
['$or' => [
['seat_target_status' => ['$eq' => true]],
['seat_target_status' => ['$eq' => false]]
]],
['camp_target_status' => ['$eq' => false]],
];
if ($from_date) {
$conditions[] = ['created_at' => ['$gte' => $from_date]];
}
return $collection->aggregate([
['$match' => ['$and' => $conditions]],
]);
})->count();
But my problem is that it returns 0 as a result; while during this period there are 16 documents.
I tried this method to get their number, but still 0 result:
$normal_banners = BannerView::Where('camp_id', $id)
->where(function ($query) {$query->where('seat_target_status', true)->orWhere('seat_target_status', false);
})
->where('camp_target_status', false)
->where("created_at", ">=", $from_date)
->count();
FYI: I converted the input date and time to ISODate. What is the mongodb data type for the field created_at.
$Fromdatetime = $request->input('from_date');
$from_date = new DateTime($Fromdatetime);
$from_date = $from_date->format(DateTime::ISO8601);
Mongodb field data type:
"updated_at": ISODate("2017-04-10T09:35:58.641Z"),
"created_at": ISODate("2017-04-10T09:35:58.641Z")
My input type is: "2017-01-07T09:08:59+0000"
Any suggestion?