We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Group By DATE AND VALUES

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

SELECT MONTH (date_done) AS mes, SUM(total) AS valor_total FROM tb_finan_movimentacoes WHERE status LIKE '%done%' AND YEAR(date_done) = YEAR(CURDATE()) GROUP BY MONTH (data_done)



609
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;