I have a collection of customers, and I need to calculate the average age of the customers for each gender.
Customer data :
{"Id_Cust":"4145","firstName":"Albade","lastName":"Maazou","gender":"female","birthday":"21/03/1981","creationDate":"2010-03-13T02:10:23.099+0000","locationIP":"41.138.53.138","browserUsed":"Internet Explorer","place":"1263"},
{"Id_Cust":"5296","firstName":"Rafael","lastName":"Oliveira","gender":"male","birthday":"08/06/1987","creationDate":"2010-02-05T06:08:26.512+0000","locationIP":"192.160.128.234","browserUsed":"Internet Explorer","place":"574"},
{"Id_Cust":"6192","firstName":"Abdul Rahman","lastName":"Budjana","gender":"male","birthday":"26/01/1990","creationDate":"2010-02-08T20:32:23.706+0000","locationIP":"27.112.77.226","browserUsed":"Firefox","place":"640"},
{"Id_Cust":"6660","firstName":"Jerzy","lastName":"Ciesla","gender":"female","birthday":"28/12/1982","creationDate":"2010-03-23T11:02:30.998+0000","locationIP":"31.192.218.139","browserUsed":"Firefox","place":"1285"},
{"Id_Cust":"8491","firstName":"Chen","lastName":"Xu","gender":"female","birthday":"27/02/1985","creationDate":"2010-03-31T15:59:11.072+0000","locationIP":"1.1.7.155","browserUsed":"Chrome","place":"437"},
{"Id_Cust":"8664","firstName":"Andrej","lastName":"Benedejcic","gender":"female","birthday":"31/08/1988","creationDate":"2010-03-24T03:12:59.456+0000","locationIP":"90.157.195.42","browserUsed":"Firefox","place":"549"},
{"Id_Cust":"10027","firstName":"Ning","lastName":"Chen","gender":"female","birthday":"08/12/1982","creationDate":"2010-03-27T12:58:05.517+0000","locationIP":"1.2.9.86","browserUsed":"Firefox","place":"332"},
{"Id_Cust":"10664","firstName":"Emperor of Brazil","lastName":"Barreto","gender":"female","birthday":"02/02/1982","creationDate":"2010-03-04T09:43:10.090+0000","locationIP":"192.111.230.73","browserUsed":"Internet Explorer","place":"576"},
{"Id_Cust":"2199023256013","firstName":"Eli","lastName":"Peretz","gender":"female","birthday":"18/01/1989","creationDate":"2010-04-28T05:16:53.514+0000","locationIP":"193.194.1.47","browserUsed":"Internet Explorer","place":"1227"},
The result must be like this:
{ "_id" : "female" , "count" : 35}
{ "_id" : "male" , "count" : 35}
Note: 35 is just an example.