我在python中使用for循环来循环pymongo查询的结果.以下是代码:
from pymongo import MongoClient
connection = MongoClient()
db = connection.Test
myDocs = db.Docs.find( { "geolocCountry" : { "$exists" : False } } )
for b in myDrives:
my_lat = b['TheGpsLog'][0]['latitude']
my_long = b['TheGpsLog'][0]['longitude']
myGeolocCountry = DoReverseGeocode(lat_start,long_start)
# Here I perform a reverse geocoding, it does not matter for this example.
# The important thing is: it returns a string, like 'US', 'UK', etc...
我的问题是,如何将变量myGeolocCountry
插入现有文档(b
)上不存在的字段geolocCountry
中?
我试过了
b['geolocCountry'] = myGeolocCountry
但它根本不起作用,甚至不会产生错误.
谢谢