Database
[{_id:1,type:"private",pid:140},{_id:2,type:"group",pid:800},{_id:3,type:"group",pid:200},{_id:4,type:"group",pid:200},{_id:5,type:"private",pid:140},{_id:6,type:"group",pid:200},{_id:7,type:"group",pid:200},{_id:8,type:"private",pid:130}]
Query
db.collection.aggregate([{$facet:{private:[{$match:{type:"private"}}],group:[{$match:{type:"group"}},{$group:{_id:"$pid",root:{$push:"$$ROOT"}}},{$project:{root:{$cond:[{$gte:[{$size:"$root"},3]},{is_too_long:true,docs:{$slice:["$root",1]}},{is_too_long:false,docs:"$root"}]}}},{$project:{root:{$map:{input:"$root.docs",in:{$mergeObjects:["$$this",{is_too_long:"$root.is_too_long"}]}}}}},{$unwind:"$root"},{$replaceRoot:{newRoot:"$root"}}]}},{$project:{root:{$concatArrays:["$private","$group"]}}},{$unwind:"$root"},{$replaceRoot:{newRoot:"$root"}}])