db.getCollection('product_protocol_new').aggregate([ {$sort:{"end_date":-1}}, {$group:{ _id:"$company_protocol", end_date:{"$first":"$$ROOT"}, }} ])