Dev-lop-er
Dev-lop-er

Reputation: 728

MongoDb count column value with multiple match condition


How to perform count on a particular column value with multiple match condition with aggregation. How to count EmpId in DeptId 1 and TimeCode 22

Upvotes: 0

Views: 39

Answers (1)

Dev-lop-er
Dev-lop-er

Reputation: 728

#Example in mongo to count number of employees in perticular department.

db.getCollection("Employee").aggregate(
    [
        {
            "$match" : {
                "DeptId " : 1
            }
        },
        {
            "$match" : {
                "TimeCode" : 22
            }
        },
        {
            "$count" : "EmployeeId"
        }
    ],
    {
        "allowDiskUse" : false
    }
);

Upvotes: 1

Related Questions