Kueri di bawah ini memecahkan masalah...$unwind digunakan untuk membagi array ke dalam masing-masing bidang sehingga $group berfungsi di sharedWith
db.getCollection('sharing').aggregate([
{
$match: { "expiryTime":{"$gte": ISODate()} }
},
{ $unwind: "$sharedWith"},
{ $group: {
// Group by fields to match on sharedWith
_id: "$sharedWith",
// Count number of matching docs for the group
count: { $sum: 1 },
// Save the _id for matching docs
docs: { $push: "$_id" }
}},
// Limit results to duplicates (more than 1 match)
{ $match: {
count: { $gt : 1 }
}}
]);