python - Mongodb中数组元素的个数统计
巴扎黑
巴扎黑 2017-04-17 17:45:07
0
1
569

集合中的记录格式如下:

{"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"的总次数)

巴扎黑
巴扎黑

membalas semua(1)
黄舟
if d['Fir'] == '0':
    print(d['FirCard_NE'].count('0402003'))
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan