开发者社区> 问答> 正文

Mongodb中数组元素的个数统计

集合中的记录格式如下:

{"ID":"0001",
 "Fir":"0",
 "Sec":"1",
 "FirCard_NE":["0402003","0101002","0201001","0503001","0402003","0204001","0204002","0301001","0101001","0402003","0501001","0501002","0503001","0503002","0501002"],
 "SecCard_NE":["0101001","0101001","0201001","0202001","0203001","0204001","0204002","0301001","0301004","0204001","0501001","0501002","0503001","0503002","0301004"]
}

现在想统计在"Fir"为"0"的情况下,FirCard_NE字段中某个数组元素在整个集合中出现的次数(如统计在"Fir"为"0"的情况下,FirCard_NE中出现"0402003"的总次数)

展开
收起
蛮大人123 2016-06-15 17:34:04 5132 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    `if d['Fir'] == '0':
    print(d['FirCard_NE'].count('0402003'))`

    2019-07-17 19:39:52
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
开源数据库 MongoDB 专场 MongoDB疑难杂症分析及优化 立即下载
阿里云MongoDB云服务构建 立即下载
饿了么高级架构师陈东明:MongoDB是如何逐步提高可靠性的 立即下载