我有一個存儲產品的文檔,一張收據裏面可以有很多產品。總計和不同計數
{"_id" : "59871e65fffe165420e0b324"
"receiptid" : "4BA/ZFY7AQ4HvfjUMTRTLg=="
"area_type" : 1
"report_type" : 3
"id_station" : 2317
"date" : "2017-08-05 00:00:00.000"
"time" : "1501979220"
"amount" : 10113958
"item" : 32
},
{"_id" : "59871e65fffe165420e0b324"
"receiptid" : "4BA/ZFY7AQ4HvfjUMTRTLg=="
"area_type" : 1
"report_type" : 3
"id_station" : 2317
"date" : "2017-08-05 00:00:00.000"
"time" : "1501979320"
"amount" : 4000000
"item" : 12
}
我想算總金額和總收據在一個查詢:
$store = array(2317);
$cursor = $collection->aggregate([
['$match' => [ 'id_station' => ['$in' => $store ], 'date' => ['$gte'=> new MongoDB\BSON\UTCDateTime(strtotime("2017-08-01")*1000), '$lte'=> new MongoDB\BSON\UTCDateTime(strtotime("2017-08-01")*1000)] ] ],
['$group' => ['_id' => ["id_station" => '$id_station'],
"amountclient"=> ['$sum' => '$amount']
]
],
['$group' => ['_id' => ["id_station" => '$id_station', "receiptid" => '$receiptid'],
"receipt"=> ['$sum' => 1]
]
]
]);
但查詢沒有顯示任何東西,我怎麼能糾正呢?
我想要的結果: { 「商店」=> XXXX, 「金額」=> XXXX, 「收到數」=> XXX}
在您提供的答案中是否有某些東西可以解決您的問題?如果是這樣,請評論答案以澄清究竟需要解決的問題。如果它確實回答了你問的問題,那麼請注意[接受你的答案](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)給你的問題問 –