Database

[{_id:1,IdShipment:"A01",hu:"C111"},{_id:2,IdShipment:"A01",hu:"C112"},{_id:3,IdShipment:"A02",hu:"D111"},{_id:4,IdShipment:"A02",hu:"D111"}]

Query

db.collection.aggregate([{"$group":{"_id":{"IdShipment":"$IdShipment","hu":"$hu"}}},{"$group":{"_id":"$_id.IdShipment","count":{"$sum":1}}}])

Result