![](/img/trans.png)
[英]How to find specific key:value 2 from python pymongo, MongoDB
[英]How to find all values for a specific key in pymongo?
我有一個mongoDB數據庫,其中存儲了幾個像這樣的JSON文件:
{ "cmd": "VarReturn",
"name": "temp",
"result": 21.511440541411535,
"coreInfo": {
"last_app": "",
"last_heard": "2016-01-18T18:41:29.559Z",
"connected": true,
"last_handshake_at": "2016-01-18T18:06:02.795Z",
"deviceID": "X",
"product_id": 6
}
}
我想查詢last_heard
和result
所有值,以獲得類似這樣的內容:
last_heard = [2016-01-18T18:41:29.559Z, 2016-01-18T18:32:28.271Z, ...]
result = [21.511440541411535, 21.108604576216564, ...]
使用distinct()
方法:
last_heard = db.collection.distinct("coreInfo.last_heard")
result = db.collection.distinct("result")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.