Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Group By DATE AND VALUES

I need to group by months and their values data from a table in MongoDB

SELECT MONTH (datedone) AS mes, SUM(total) AS valortotal FROM tbfinanmovimentacoes WHERE status LIKE '%done%' AND YEAR(datedone) = YEAR(CURDATE()) GROUP BY MONTH (datadone)



194
Accepted
answer

SOLVED...

    $data = Financeiro::aggregate(array(  
       array(
          '$match' => array(
                'status_financeiro' => 'Pago'
            )
       ),
       array(
            '$group' => array(
                '_id' => array(
                        'mes' => array('$month'=> '$Conciliacao'),
                        'ano' => array('$year'=> '$Conciliacao')
                ),
                'total' => array('$sum' => '$VlrTransacao'),
                'count' => array('$sum' => 1)
            )
        ),
        array(
            '$sort' => array('ano' => -1)
        )
    ));

    return $data;