1、我是初学者,自学点点滴滴,目前遇到个问题,
mongodb数据库有这些的数据,其中huifuzhuagntai的0是未回复的意思,1是已回复的意思
{id:1,huifuzhuangtai:0,title:标题}
{id:1,huifuzhuangtai:1,title:标题}
{id:1,huifuzhuangtai:1,title:标题}
{id:1,huifuzhuangtai:1,title:标题}
{id:1,huifuzhuangtai:1,title:标题}
{id:1,huifuzhuangtai:1,title:标题}
2、我用管道筛选的数据,
def zong2(): pipeline=[ {'$group':{'_id':'$huifuzhuangtai','counts':{'$sum':1}}} ] for i in item_info.aggregate(pipeline): data={ 'name':i['_id'], 'counts':i['counts'] } print(data) zong2()
得到的结果是
{'name': 1, 'counts': 5}
{'name': 0, 'counts': 1}
我想得到的结果是
{'已回复': 1, 'counts': 5}
{'未回复': 0, 'counts': 1}
这个怎么弄,请求大侠帮忙看看,小白太笨了
或