如何解决似乎没有为nosql中的聚合函数加起来
im是nosql的新手,并且希望提供有关聚合函数的一些指导。我尝试运行此聚合函数,但总的来说,total_new_cases不能在某些月份汇总,当实际上有要累加的new_cases值时显示为null。
db.world.aggregate([
{$group:
{
_id:{groupbymonth: {$month:"$date"}},total_new_cases: {$sum:"$new_cases"},continent: "$continent"
}
},{$project:
{
_id: 1,total_new_cases: 1
}
},{$sort:{"_id":1}})
以下是输出:
{
"_id" : {
"groupbymonth" : 1
},"total_new_cases" : null
},/* 2 */
{
"_id" : {
"groupbymonth" : 2
},/* 3 */
{
"_id" : {
"groupbymonth" : 3
},/* 4 */
{
"_id" : {
"groupbymonth" : 4
},/* 5 */
{
"_id" : {
"groupbymonth" : 5
},/* 6 */
{
"_id" : {
"groupbymonth" : 6
},/* 7 */
{
"_id" : {
"groupbymonth" : 7
},/* 8 */
{
"_id" : {
"groupbymonth" : 8
},/* 9 */
{
"_id" : {
"groupbymonth" : 12
},"total_new_cases" : 54
}
这是有关变量的某些上下文的集合的摘录:
{
"_id" : ObjectId("5f4a06e03acddb5eec5561c5"),"iso_code" : "AFG","continent" : "Asia","location" : "Afghanistan","date" : ISODate("2019-12-31T00:00:00.000+08:00"),"total_cases" : 0,"new_cases" : 0,"new_cases_smoothed" : 0,"total_deaths" : 0,"new_deaths" : 0,"new_deaths_smoothed" : 0,"total_cases_per_million" : 0,"new_cases_per_million" : 0,"new_cases_smoothed_per_million" : 0,"total_deaths_per_million" : 0,"new_deaths_per_million" : 0,"new_deaths_smoothed_per_million" : 0,"new_tests" : NaN,"total_tests" : NaN,"total_tests_per_thousand" : 0,"new_tests_per_thousand" : 0,"new_tests_smoothed" : 0,"new_tests_smoothed_per_thousand" : 0,"tests_per_case" : 0,"positive_rate" : 0,"tests_units" : NaN,"stringency_index" : 0,"population" : 38928341,"population_density" : 54.422,"median_age" : 18.6,"aged_65_older" : 2.581,"aged_70_older" : 1.337,"gdp_per_capita" : 1803.987,"extreme_poverty" : "","cardiovasc_death_rate" : 597.029,"diabetes_prevalence" : 9.59,"female_smokers" : NaN,"male_smokers" : NaN,"handwashing_facilities" : 37.746,"hospital_beds_per_thousand" : 0.5,"life_expectancy" : 64.83
}
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。