2012-11-14 142 views
0

我收集的實時微博和存入集合我現在想提取收集從記錄中的信息中提取數據:從蒙戈集合

"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) 

但這並不返回,其中邊框是關鍵座標。

我怎樣才能得到這些數據?

感謝

回答

1

你將不得不這樣做

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"] 
+0

謝謝你的作品.....所以我需要有也完成了:{「place.bounding_box.coordinates」:1},而不僅僅是{「coordinates」:1}。 – user94628