【发布时间】:2016-11-16 20:54:27
【问题描述】:
这是我的数据格式:
"request" : {
"_id" : 1003,
"user" : {
"username" : "",
"password" : "",
"_id" : 1111,
"gender" : "male",
},
"request" : {
"merchantid" : "TA456",
"txnAmount" : 18000,
"fee" :0,
"IssuerID" : "18801111",
"bankID" : "888888",
}
},
"confirmation" : true
}`
我无法通过“request.user._id”获得“request.request.txnAmount”组的总和。
这是我的查询:
db.getCollection('megabank_response').aggregate(
[ { $group : {
_id : "request.user._id",
totalPrice: { $sum: "request.request.txnAmount"},
count: { $sum: 1 }
}
}
])
并得到结果:
{
"_id" : "request.user._id",
"total Price" : 0,
"count" : 4.0
}
谁能帮助我为什么我的查询无法计算总和?
【问题讨论】:
-
txnAmount是String转换它的数字,然后检查您的聚合查询 -
我已经试过了,结果还是一样
标签: mongodb aggregation-framework