Keeping field in mongodb group by
问题 I have the following kind of docs in a collection in mongo db { _id:xx, iddoc:yy, type1:"sometype1", type2:"sometype2", date: { year:2015, month:4, day:29, type:"day" }, count:23 } I would like to do a sum over the field count grouping by iddoc for all docs where: type1 in ["type1A","type1B",...] where type2 in ["type2A","type2B",...] date.year: 2015, date.month: 4, date.type: "day" date.day between 4 and 7 I would like then to sort these sums. I know now how to do this (see this question) db