0) Read the official MongoDB documentation for understand what db commands you can use and what parameters they requires - https://docs.mongodb.com/manual/reference/command/
1) Wrong:
$cmd = new \MongoDB\Driver\Command([
'aggregate' => 'collection',
'pipeline' => ['$group' => ['_id' => null, 'count' => ['$sum' => '$total']]]
]);
because pipeline is array of objects in json words (index array of associative arrays in php words) - pipeline: [ {<stage>}, ... ]
What does it mean? It means that 'pipeline' must be like this:
[
['$group' => ['_id' => null, 'count' => ['$sum' => '$total']]], // this is {<stage>}
['$match' => [...]], // and this
...
[...] // and all of that
]
Just see https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/
2) The first pair in associative array for __construct's argument $document (if it is an array) must be a command name (e. g. 'count' => 'collectionName' or 'findAndModify' => 'collectionName'). I found this out experimentally, but you can examine source code https://github.com/mongodb/mongo-php-driver/blob/master/src/MongoDB/Command.c for understand why it happens.