{
"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"}
}
}])
我试着找到总价值。任何人都可以帮助找到总价值。也可以通过明智的方式找到值。