我有以下文件
{
"_id": "57b4c5f0291ebb13110b888e",
"first": "John",
"last": "Smith",
"email": "John.Smith@gmail.com",
"fulfillments": [
{
"_id": "57b683e531a5a21679b78e6d",
"created_by_name": "John Smith",
"created_by_id": "57b4c5f0291ebb23110b888e",
"fulfilled_by_name": "John Smith",
"fulfilled_by_id": "57b4c5f0291ebb13110b888e",
"date": new Date("2016-08-23T13:58:15-0700")
}
]
}
我有一个mongo查询,我只想返回尚未发生的履行列表。这意味着履行嵌入文档中的date
属性大于当前时间。
db.users.aggregate([
{ $match : { "_id" : "57b4c5f0291ebb13110b888e" } },
{ $project : {
"fulfillments" : {
$filter : {
"input" : "$fulfillments",
"as" : "item",
"cond" : ...SOMETHING HERE TO FILTER ON 'date'
}
}
}
},
{ $unwind : "$fulfillments" },
{ $project : {
"created_by_name" : "$fulfillments.created_by_name",
"created_by_id" : "$fulfillments.created_by_id",
"fulfilled_by_name" : "$fulfillments.fulfilled_by_name",
"fulfilled_by_id" : "$fulfillments.fulfilled_by_id",
"date" : "$fulfillments.date"
}
}
])
我无法弄清楚仅过滤date
尚未发生的履行的正确方法。
答案 0 :(得分:1)
以下内容应该为您提供所需的结果
Route
Route::get('datatables',['uses'=>'DatatablesController@getIndex', 'as' => 'datatables']);
Route::get('datatables/{data}',['uses'=>'DatatablesController@anyData', 'as' => 'datatables.data']);
Controller
public function anyData()
{
$users = User::select(['id', 'name', 'email', 'created_at', 'updated_at'])->get();
return Datatables::of($users)->make();
}
JS
$('#users-table').DataTable({
processing: true,
serverSide: true,
ajax: '{!! url('datatables/data') !!}'
});