Database

[{"something":"else","stuff":"I don't want","a_thing":[{"thing":"a record","cat":"type A"},{"thing":"an other record","cat":"type A"},{"thing":"yet other record","cat":"type B"},{"thing":"more records","cat":"type A"},{"thing":"last record","cat":"type C"}]}]

Query

db.collection.aggregate([{$set:{keys:{$setUnion:["$a_thing.cat"]},}},{$project:{res:{$map:{input:"$keys",as:"key",in:{k:"$$key",v:{$reduce:{input:"$a_thing",initialValue:[],in:{$concatArrays:["$$value",{$cond:[{$eq:["$$this.cat","$$key"]},[{thing:"$$this.thing"}],[]]}]}}}}}}}},{$project:{res:{$map:{input:"$res",in:{k:"$$this.k",v:{sub_total:{$size:"$$this.v"},values:"$$this.v"}}}}}},{$project:{res:{"$arrayToObject":"$res"}}},])

Result