计算mongodb

时间:2018-05-12 07:31:24

标签: javascript mongodb object

{
        "id" : "12345"
        "energy" : "electricity",
        "type" : "lighting",
        "value" : 24324
    }, 
    {
        "id" : "12345"
        "energy" : "electricity",
        "type" : "equipment",
        "value" : 24324
    }, 
    {
        "energy" : "electricity",
        "type" : "fans",
        "value" : 24324
    }, 
    {
        "id" : "12345"
        "energy" : "electricity",
        "type" : "distribution",
        "value" : 24324
    }, 
    {
        "id" : "12345"
        "energy" : "electricity",
        "type" : "chiller",
        "value" : 24324
    }, 
    {
       "id" : "12345"
        "energy" : "electricity",
        "type" : "other",
        "value" : 24324
    }

这是我查询总价值的查询。我使用$ project。

  db.invoices.aggregate([
    {
    $project: {
        total: {$sum : "$value"}
    }
}])

我试着找到总价值。任何人都可以帮助找到总价值。也可以通过明智的方式找到值。

0 个答案:

没有答案