![](/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.