Database

[{"_id":ObjectId("6451529ad254d565bd12156b"),"contentType":"Json","fieldName":"xxx","method":"GET","value":"Car","location":"header","code":404},{"_id":ObjectId("6451529ad254d565bd12156d"),"contentType":"Json","fieldName":"xxx","method":"GET","value":"Plane","location":"header","code":404},{"_id":ObjectId("6451529ad254d565bd121570"),"contentType":"Json","fieldName":"yyy","method":"GET","value":"Smile","location":"header","code":404},{"_id":ObjectId("6451529ad254d565bd13156b"),"contentType":"Empty","fieldName":"zzz","method":"POST","value":"Train","location":"header","code":200},{"_id":ObjectId("6451529ad254d5651112156a"),"contentType":"Empty","fieldName":"zzz","method":"POST","value":"Player","location":"body","code":200},{"_id":ObjectId("6451529ad254d565bd12166d"),"contentType":"Empty","fieldName":"zzz","method":"POST","value":"Van","location":"body","code":404},{"_id":ObjectId("6451529ad254d565bd121670"),"contentType":"Json","fieldName":"name4","method":"GET","value":"Van","location":"body","code":200}]

Query

db.collection.aggregate([{$match:{contentType:"Json"}},{$group:{_id:{fieldName:"$fieldName",location:"$location"},values:{$push:"$value"}}},{$replaceRoot:{newRoot:{$mergeObjects:["$_id",{values:"$values"}]}}}])

Result