I have a database of over 2000 reviews for products on an online store, and I am trying to find all of the users who have written minimum 5 reviews, and I would like to list the
I guess you need to run this aggregation:
db.review.aggregate([
{
$group: {
_id: "$SH_reviewerID",
name: {
$first: "$SH_reviewerName"
},
number: {
$sum: 1
}
}
},
{
$match: {
number: {
$gte: 5
}
}
},
//Optional - Order views descendant
{
$sort: {
number: -1
}
},
//Optional - Change field names
{
$project: {
_id: 0,
SH_reviewerID: "$_id",
SH_reviewerName: "$name",
SH_reviewerViews: "$number"
}
}
])
MongoPlayground