The following data format, I want tofill_time
For group by,fill_time
Fields are nested at the third level.
Business Requirements: If there are multiple different records in this recordfill_time
, you need to group statistics many times. For example, the following data, statistics twice, respectively15 March
And17 March
One for each. Can you use it, pleaseaggregate
Implementation?
{
"_id": "56e932f42ec56a4afc00a083",
"binding_time": "2016-03-16 18:18:28",
"categorys": [
{
"category_code": "003",
"category_name": "cervical spondylosis",
"datas": [
{
"fill_time": "2016-03-17 10:47:59",
"form_code": "6",
"plan_code": "P45",
"results": []
},
{
"fill_time": "2016-03-17 10:48:25",
"form_code": "3",
"plan_code": "P45",
"results": []
}
],
"edc_patId": "P015830",
"start_time": "2014-4-21 13:41:42"
},
{
"category_code": "004",
"category_name": "spinal tumor",
"datas": [
{
"fill_time": "2016-03-15 10:48:48",
"form_code": "34",
"plan_code": "P47",
"results": []
},
{
"fill_time": "2016-03-15 10:49:14",
"form_code": "36",
"plan_code": "P47",
"results": []
}
],
"edc_patId": "P038894",
"start_time": "2014-4-21 13:41:42"
}
],
"patient_id": "000997785203",
"person_name": "Zhang San",
"project_code": "SYGK",
"subscribe": false
}
aggregate([ {$unwind:"$categorys"}, {$unwind:"$categorys.datas"}, {$project:{ 'date':{$substr : ["$categorys.datas.fill_time",0,10]} } }, {$group:{ _id:'$date', "count":{$sum:1} } }])