Hi Tamil,
As mentioned by Alan, you can use $match pipeline operator to filter documents.
For example, the following selects documents to process, then pipes the results to the $group pipeline operator to generate count.
db.collection.aggregate( [
{ $match: { $or: [ { score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } } ] } },
{ $group: { _id: null, count: { $sum: 1 } } }
] );
See Aggregation pipeline operators for a list of available operators in MongoDB v3.2.
Also worth mentioning:
$match as early in the pipeline as possible, because $match limits the total number of documents in the pipeline and minimize the amount of processing down the pipe. $match at the very beginning of the pipeline, the query can take advantage of indexes. If you still have any questions, can you provide the following:
Regards,
Wan.
db.Employee.aggregate(
[
{"$match": { "division": "Chennai" } },
{"$group": { "_id": "$city", "count": {"$sum": 1} } }
]
)