[英]Extracting data from a mongo collection
I'm collecting real-time tweets and storing into a collection I now want to extract the information from a record in the 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" }
I just want the coordiante information, so using pymongo I try to do: 我只想要coordiante信息,所以我尝试使用pymongo:
cursor = coll.find({"place.bounding_box.type" : "Polygon"},{"coordinates" : 1}, tailable = True, timeout = False)
But this doesn't return the coordinates where the bounding box is the key. 但这不会返回以边框为键的坐标。
How could I get this data returned? 我怎样才能得到这些数据?
Thanks 谢谢
You will have to do this 您将必须这样做
cursor = coll.find({"place.bounding_box.type" : "Polygon"}, {"place.bounding_box.coordinates" : 1})
This will return data in the format: 这将以以下格式返回数据:
>> cursor.next()
"place" : {"bounding_box" : { "coordinates" : [ [ [ -77.119759, 38.791645 ], [ -76.909393, 38.791645 ], [ -76.909393, 38.995548 ], [ -77.119759, 38.995548 ] ] ]}
So to get the data you seem to want: 因此,要获取您似乎想要的数据:
for doc in cursor:
print doc["place"]["bounding_box"]["coordinates"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.