簡體   English   中英

如何在pymongo中查找特定鍵的所有值?

[英]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_heardresult所有值,以獲得類似這樣的內容:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM