I have a document related to the role or designations of employees. This is the document structure.
{ \"_id\" : ObjectId(\"5660c2a5b6fcba2d47baa2d9\"),
You could use this:
db.employee_role.aggregate( [ { $match: { role_title: "Carpenter" } }, { $group: { _id: "$role_title", total: { $sum: { $size: "$employees"} } } } ] )