mysql 转写 mongo 语句. group by 多字段!

之前一直用mysql,但在业务中增加了mongo 对于 mongo不熟悉。属于边用边看的!

SELECT `*`,GROUP_CONCAT(`invoice_number`) as `invoice_number_all`,ROUND(SUM(`invoice_amount`)/100,2) as `invoice_amount_all`,ROUND(SUM(`premium_amount`)/100,2) as `premium_amount_all`  FROM `t_invoice` WHERE `id` != 0  GROUP BY `insurer_id`,`region_id`,`invoice_company_id`,`data_type`,`invoice_date`,`invoice_remark` ORDER BY `invoice_date` DESC LIMIT 0,15

上面是原sql语句。
我看聚合后写了个

db.t_invoice.aggregate(
{
    "$group": {
        _id: {
            insurer_id:"$insurer_id",
            region_id: "$region_id",
            invoice_company_id:"$invoice_company_id",
            data_type: "$data_type",
            invoice_date: "$invoice_date",
            invoice_remark: "$invoice_remark",
            },
            count:{$sum:1}
        }
    }
})

但是我不知道如何增加字段
image.png
得出结果也不是我想要的,更另说mysql的拼接 计算写法了

阅读 112
评论 11月11日提问
    撰写回答

    登录后参与交流、获取后续更新提醒

    MongoDB 技术问答
    合作问答

    MongoDB 官方中文社区 和 SegmentFault 联合推出的 MongoDB 技术交流平台。 这是一个以社区力量为主,但...