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

我只想要坐标信息,所以使用 pymongo 我尝试这样做:

 cursor = coll.find({"place.bounding_box.type" : "Polygon"},{"coordinates" : 1}, tailable = True, timeout = False)

但这不会返回边界框是关键的坐标。

我怎样才能得到这些数据返回?

谢谢

4

1 回答 1

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"]
于 2012-11-14T16:19:26.513 回答