![](/img/trans.png)
[英]Retrieve data from a collection(mongo),modify the returned object and insert it into another mongo collection
[英]Extracting data from a mongo collection
我正在收集實時推文並將其存儲到集合中,現在我想從集合中的記錄中提取信息:
"place" : { "country_code" : "US", "url" : "http://api.twitter.com/1/geo /id/01fbe706f872cb32.json", "country" : "United States", "place_type" : "city", "bounding_box" : { "type" : "Polygon", "coordinates" : [ [ [ -77.119759, 38.791645 ], [ -76.909393, 38.791645 ], [ -76.909393, 38.995548 ], [ -77.119759, 38.995548 ] ] ] }, "full_name" : "Washington, DC", "attributes" : { }, "id" : "01fbe706f872cb32", "name" : "Washington" }
我只想要coordiante信息,所以我嘗試使用pymongo:
cursor = coll.find({"place.bounding_box.type" : "Polygon"},{"coordinates" : 1}, tailable = True, timeout = False)
但這不會返回以邊框為鍵的坐標。
我怎樣才能得到這些數據?
謝謝
您將必須這樣做
cursor = coll.find({"place.bounding_box.type" : "Polygon"}, {"place.bounding_box.coordinates" : 1})
這將以以下格式返回數據:
>> cursor.next()
"place" : {"bounding_box" : { "coordinates" : [ [ [ -77.119759, 38.791645 ], [ -76.909393, 38.791645 ], [ -76.909393, 38.995548 ], [ -77.119759, 38.995548 ] ] ]}
因此,要獲取您似乎想要的數據:
for doc in cursor:
print doc["place"]["bounding_box"]["coordinates"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.