How can I count over multiple fields in mongo?
You can use $cond + $eq to return either 1 or 0 to $sum operator:
db.collection.aggregate([
  {
    $group: {
      _id: "$DeviceType",
      DeviceStatusOnCount: { $sum: { $cond: [ { $eq: [ "$DeviceStatus", "On" ] }, 1, 0 ] } },
      DeviceStatusOffCount: { $sum: { $cond: [ { $eq: [ "$DeviceStatus", "Off" ] }, 1, 0 ] } },
      DeviceStatusInRepairCount: { $sum: { $cond: [ { $eq: [ "$DeviceStatus", "InRepair" ] }, 1, 0 ] } }
    }
  },
  {$addFields: {DeviceType: '$_id'}}, {$project: {_id:0}}
])

Test: mongoplayground

I am trying to write a mongo query to help produce a report from the data.
The documents look something like this:
[{
    "DeviceType" : "A",
    "DeviceStatus" : "On"
},
{
    "Device Type" : "B",
    "Device Status" : "On"
},
{
    "DeviceType" : "A",
    "DeviceStatus" : "Off"
},
{
    "DeviceType" : "A",
    "DeviceStatus" : "On"
}]

The DeviceType field can take any string value and the DeviceStatus field can be any one of On, Off or InRepair. I want to write a mongo query that displays DeviceStatus count for each one of the devices. The result should be something like this:
[{
    "DeviceType" : "A",
    "DeviceStatusOnCount" : "15",
    "DeviceStatusOffCount" : "13",
    "DeviceStatusInRepairCount" : "12",
},
{
    "DeviceType" : "B",
    "DeviceStatusOnCount" : "6",
    "DeviceStatusOffCount" : "14",
    "DeviceStatusInRepairCount" : "2",
}]

How can I achieve this in mongo?
My current query can only group based on the DeviceType:
db.Collection_Name.aggregate([
    { $group: { _id: "$DeviceType", count: { $sum: 1 } } }
])

