我想知道是否可能只有查询结果显示在列表中返回的值。只显示查询后的列表中的值mongodb
我运行的是以下几点:
a = ast.literal_eval(json.dumps(list(db.bastion.find({ },{ 'counter': 1, '_id': False }))))
它返回类似这样:
[{'counter': 10447}, {'counter': 25375}, {'counter': 11963}, {'counter': 17297},
{'counter': 5893}, {'counter': 19955}, {'counter': 5159}, {'counter': 3988},
{'counter': 7638}, {'counter': 8250}, {'counter': 29514}, {'counter': 4940},
{'counter': 12834}, {'counter': 31153}, {'counter': 8588}, {'counter': 17585},
{'counter': 7099}, {'counter': 18580}, {'counter': 2575}, {'counter': 3696},
{'counter': 5071}, {'counter': 4074}, {'counter': 15355}, {'counter': 16520},
{'counter': 13850}, {'counter': 18639}, {'counter': 22640}, {'counter': 13962},
{'counter': 14354}, {'counter': 10945}, {'counter': 10330}]
所以我想仅仅是价值,而不是键名计数器显示这样我就可以计算第95个百分点,执行以下操作:
for i in a:
print np.percentile(map(int,i),95)
我认为一个mongo查询不能做到这一点。所以无论是映射客户端还是使用map-reduce。 – hgoebl
为什么'ast.literal_eval(json.dumps(...))'?对我来说似乎完全是多余的。 – Rafa
嗨,那只是摆脱你{XXXXXXX}显示除了没有任何目的。 – user3105272