How to get $count along with other properties?

Trying to get total count along with some other properties.

    db.collection.aggregate([
      {
        $match: {
          "dob.age": 59
        }
      },
      {
        $count: "total"
      },
      {
        $project: {
          "dob.age": 1,
          "total":1
        }
      }
    ])

Doesn’t seem to be working one way or another.

Also posted on Stack Overflow.

Hi @jim_rock,

I see that the answer was provided on Stack Overflow:

db.collection.aggregate([
  {
    $match: {
      "dob.age": 59
    }
  },
  {
    $group: {
      _id: "$dob.age",
      total: {
        $sum: 1
      }
    }
  },
  {
    $project: {
      _id: 0,
      age: "$_id",
      "total": 1
    }
  }
])

Please let us know if you needed something else.

Best regards,
Pavel