I\'m in this scenario right now: I have a collection X:
{ _id:ObjectId(\'56edbb4d5f084a51131dd4c6\'), userRef:ObjectId(\'56edbb4d5f084a51131dd4c6\'), seria
You can simply use $toString to apply $concat in aggregation on ObjectIDs in the following way -
$group: { '_id': { '$concat': [ { '$toString' : '$userRef' }, '-', { '$toString' : '$serialNumber'} ] }, }