我想知道是否可能只有查詢結果顯示在列表中返回的值。只顯示查詢後的列表中的值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