我有一个存储产品的文档,一张收据里面可以有很多产品。总计和不同计数
{"_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)给你的问题问 –