I have been able to create an aggregation query to count by a field of my data object.
db.getCollection.aggregate([
{"$group" : {"_id": "$attr", "count": {"$sum" : 1}}},
{"$sort": {"count": -1}}
])
which results in a {_id,count}
based documents sorted in descending order of count. All good until now.
What I am trying next is to filter
in (match) only those documents which have count above N
(say 100) threshold. But when I execute:
db.getCollection.aggregate([
{"$group" : {"_id": "$attr", "count": {"$sum" : 1}}},
{"$sort": {"count": -1}},
{"$match": {"count": {$gte:["count",100]}}}
])
the query returns empty results. What is the way to achieve this? I have also tried usinng $filter
instead of $match
to no success.