在這段代碼中,我有一個Doctor文檔,文檔裏面有一個醫生的病人列表。在這種情況下,我想查看我陣列中所有患者的平均年齡。我該怎麼做?如何獲得數組中值的平均值?
{
"_id" : ObjectId("57113238bde91693e9ff69e7"),
"docname" : "Arthur Hovsepyan",
"job_desc" : "Hepatologist",
"sex" : "male",
"jobtype" : "fulltime",
"office" : "room 448",
"email" : "[email protected]",
"phone_number" : 862124343,
"address" : "68 Peterburg street,waterford",
"hours" : 12,
"patients" : [
{
"name" : "Jenny Power",
"ward_no" : 1,
"sex" : "female",
"termdays" : 2,
"illness_type" : "minor",
"age" : 22,
"phone_number" : 877285221,
"address" : "63 Johnston street ,Waterford"
},
{
"name" : "Marie Peters",
"ward_no" : 2,
"sex" : "female",
"termdays" : 0,
"illness_type" : "minor",
"age" : 21,
"phone_number" : 862145992,
"address" : "99 Grange,Waterford"
},
{
"name" : "Philip John",
"ward_no" : 2,
"sex" : "male",
"termdays" : 10,
"illness_type" : "serious",
"age" : 31,
"phone_number" : 861125981,
"address" : "12 Monvoy Bridge,Waterford"
},
{
"name" : "Marta Peters",
"ward_no" : 3,
"sex" : "female",
"termd7ays" : 0,
"illness_type" : "minor",
"age" : 31,
"phone_number" : 862125981,
"address" : "100 Grange Manor,Waterford"
}
]
}
當我嘗試,我得到的零平均 – ebatinstitute